< Summary

Class:WinSolutions.Sveta.Server.Services.Implements.MovementItemService
Assembly:WinSolutions.Sveta.Server
File(s):/opt/dev/sveta_api_build/WinSolutions.Sveta.Server/Services/Implements/MovementItemService.cs
Covered lines:0
Uncovered lines:51
Coverable lines:51
Total lines:76
Line coverage:0% (0 of 51)
Covered branches:0
Total branches:12
Branch coverage:0% (0 of 12)

Metrics

MethodLine coverage Branch coverage
.ctor(...)0%100%
GetMovementItem()0%100%
GetMovementItems()0%100%
CreateMovementItem()0%0%
UpdateMovementItem()0%100%
DeleteMovementItem()0%0%
MovementItemExists()0%100%

File(s)

/opt/dev/sveta_api_build/WinSolutions.Sveta.Server/Services/Implements/MovementItemService.cs

#LineLine coverage
 1using Microsoft.EntityFrameworkCore;
 2using Microsoft.Extensions.Logging;
 3using System;
 4using System.Collections.Generic;
 5using System.Linq;
 6using System.Text;
 7using System.Threading.Tasks;
 8using WinSolutions.Sveta.Server.Data.DataModel.Contexts;
 9using WinSolutions.Sveta.Server.Data.DataModel.Entities;
 10using WinSolutions.Sveta.Server.Services.Interfaces;
 11using WinSolutions.Sveta.Common;
 12
 13namespace WinSolutions.Sveta.Server.Services.Implements
 14{
 15    public class MovementItemService : SvetaServiceBase
 16    {
 17        private readonly SvetaDbContext _db;
 18        private readonly ILogger<MovementItemService> _logger;
 19        public MovementItemService(SvetaDbContext db, ILogger<MovementItemService> logger, IAuthenticationService authen
 020            : base(authenticationService)
 021        {
 022            _db = db;
 023            _logger = logger;
 024        }
 025        public async Task<MovementItem> GetMovementItem(long id) => await _db.MovementItems
 026            .Include(d => d.Good)
 027            .ThenInclude(Good => Good.UnitsKind)
 028            .Include(d => d.Good)
 029            .ThenInclude(Good => Good.VatsKind)
 030            .Include(d => d.RecState)
 031            .Where(e => !e.IsDeleted)
 032            .FirstOrDefaultAsync(d => d.Id == id);
 033        public async Task<List<MovementItem>> GetMovementItems(int page, int limit) => await _db.MovementItems
 034            .AsNoTracking()
 035            .Include(d => d.Good)
 036            .ThenInclude(Good => Good.DefaultBarCode)
 037            .Include(d => d.Good)
 038            .ThenInclude(Good => Good.GoodBarcodes)
 039            .ThenInclude(barcode =>  barcode.BarCode)
 040            .Include(d => d.Good)
 041            .ThenInclude(Good => Good.UnitsKind)
 042            .Include(d => d.Good)
 043            .ThenInclude(Good => Good.VatsKind)
 044            .Include(d => d.RecState)
 045            .Where(d => !d.IsDeleted)
 046            .Skip(page * limit)
 047            .Take(limit)
 048            .ToListAsync();
 49        public async Task CreateMovementItem(MovementItem item)
 050        {
 051            if (item.RecState != null)
 052                _db.Entry(item.RecState).State = item.RecState.Id == 0 ? EntityState.Detached : EntityState.Unchanged;
 053            await _db.MovementItems.AddAsync(item);
 054            await _db.SaveChangesAsync(CurrentUserId);
 055        }
 56        public async Task UpdateMovementItem(MovementItem item)
 057        {
 058            _db.MovementItems.Update(item);
 059            await _db.SaveChangesAsync(CurrentUserId);
 060        }
 61        public async Task DeleteMovementItem(MovementItem data)
 062        {
 063            if (!(await MovementItemExists(data.Id)))
 064            {
 065                throw new ArgumentException($"Record #{data.Id} not found");
 66            }
 067            _db.Entry(data).State = EntityState.Deleted;
 068            await _db.SaveChangesAsync(CurrentUserId);
 069        }
 070        public async Task<bool> MovementItemExists(long id) => await _db.MovementItems
 071            .AsNoTracking()
 072            .Where(e => !e.IsDeleted)
 073            .Where(d => d.Id == id)
 074            .AnyAsync();
 75    }
 76}