< Summary

Class:WinSolutions.Sveta.Server.Services.Implements.MovementStatusJournalService
Assembly:WinSolutions.Sveta.Server
File(s):/opt/dev/sveta_api_build/WinSolutions.Sveta.Server/Services/Implements/MovementStatusJournalService.cs
Covered lines:47
Uncovered lines:15
Coverable lines:62
Total lines:97
Line coverage:75.8% (47 of 62)
Covered branches:8
Total branches:16
Branch coverage:50% (8 of 16)

Metrics

MethodLine coverage Branch coverage
.ctor(...)100%100%
GetMovementStatusJournals()0%0%
GetMovementStatusJournal()0%100%
GetAllActive()0%100%
GetMovementStatusJournalCount()0%100%
GetMovementStatusJournal()100%100%
GetMovementStatusJournal()0%100%
Create()100%66.66%
SetRecordInactive()0%0%
PrepareQuery(...)100%100%

File(s)

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

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using System.Text;
 5using System.Threading.Tasks;
 6using Microsoft.EntityFrameworkCore;
 7using Microsoft.Extensions.Logging;
 8using WinSolutions.Sveta.Server.Data.DataModel.Contexts;
 9using WinSolutions.Sveta.Server.Data.DataModel.Entities;
 10using WinSolutions.Sveta.Server.Data.DataModel.Kinds;
 11using WinSolutions.Sveta.Server.Services.Interfaces;
 12using WinSolutions.Sveta.Common;
 13
 14namespace WinSolutions.Sveta.Server.Services.Implements
 15{
 16    public class MovementStatusJournalService : SvetaServiceBase, IMovementStatusJournalService
 17    {
 18        private readonly ILogger<MovementStatusJournalService> _logger;
 19        private readonly SvetaDbContext _db;
 20
 21        public MovementStatusJournalService(ILogger<MovementStatusJournalService> logger,
 22            SvetaDbContext db,
 11223            IAuthenticationService authenticationService):base(authenticationService)
 11224        {
 11225            _db = db;
 11226            _logger = logger;
 11227        }
 28
 29        public async Task<List<MovementStatusJournal>> GetMovementStatusJournals(int page, int limit, string filter) =>
 030            await PrepareQuery(filter)
 031                .Skip((page < 2 ? 0 : page - 1) * limit )
 032                .Take(limit)
 033                .ToListAsync();
 34
 35        public async Task<List<MovementStatusJournal>> GetMovementStatusJournal(DateTime startDate, bool activeOnly = fa
 036            await PrepareQuery(activeOnly: activeOnly)
 037                .Where(d => d.CreationDateTime >= startDate)
 038                .ToListAsync();
 39
 040        public async Task<List<MovementStatusJournal>> GetAllActive() => await PrepareQuery(activeOnly: true).ToListAsyn
 41
 042        public async Task<int> GetMovementStatusJournalCount(string filter) => await PrepareQuery(filter).CountAsync();
 43
 4944        public async Task<List<MovementStatusJournal>> GetMovementStatusJournal(long movementId) => await PrepareQuery()
 4945            .Where(d => d.Movement.Id == movementId)
 4946            .ToListAsync();
 047        public  async Task<MovementStatusJournal> GetMovementStatusJournal(long movementId, MovementStatus status) => aw
 048            .FirstOrDefaultAsync(d => d.Movement.Id == movementId && d.StatusCurrent.Id == status.Id);
 49        public async Task Create(MovementStatusJournal journal)
 34850        {
 34851            _db.Entry(journal.Movement).State = EntityState.Unchanged;
 34852            _db.Entry(journal.StatusCurrent).State = EntityState.Unchanged;
 34853            journal.RecState = await _db.refRecordsState.FindAsync((long) RecordState.Active);
 34854            var oldJournal = await _db.MovementStatusJournals.Where(d => d.Movement.Id == journal.Movement.Id).ToListAsy
 34855            if (oldJournal?.Count > 0)
 24656            {
 24657                var incative = await _db.refRecordsState.FindAsync((long)RecordState.Inactive);
 188058                foreach (var old in oldJournal)
 57159                {
 57160                    old.RecState = incative;
 57161                }
 24662            }
 34863            await _db.MovementStatusJournals.AddAsync(journal);
 34864            await _db.SaveChangesAsync(CurrentUserId);
 34865        }
 66
 67        public async Task SetRecordInactive(MovementStatusJournal item)
 068        {
 069            item.RecState = await _db.refRecordsState.FirstOrDefaultAsync(d => d.Id == (long) RecordState.Inactive);
 070            await _db.SaveChangesAsync(CurrentUserId);
 071        }
 72
 4973        private IQueryable<MovementStatusJournal> PrepareQuery(string filter = default, bool activeOnly = false) => _db.
 4974            .Include(d => d.Movement)
 4975            .ThenInclude(Movement => Movement.RecState)
 4976            .Include(d => d.Movement)
 4977            .ThenInclude(Movement => Movement.MovementType)
 4978            .Include(d => d.Movement)
 4979            .ThenInclude(Movement => Movement.Customer)
 4980            .Include(d => d.Movement)
 4981            .ThenInclude(Movement => Movement.Supplier)
 4982            .Include(d => d.Movement)
 4983            .ThenInclude(Movement => Movement.Parent)
 4984            .ThenInclude(Parent => Parent.MovementStatus)
 4985            .Include(d => d.Movement)
 4986            .ThenInclude(Movement => Movement.Notes)
 4987            .Include(d => d.Movement).ThenInclude(Movement => Movement.Sender)
 4988            .Include(d => d.StatusCurrent)
 4989            .Include(d => d.RecState)
 4990            .Where(d => !d.IsDeleted && !d.Movement.IsDeleted)
 4991            .Where(d => !activeOnly || d.RecState.Id == (long)RecordState.Active)
 4992            .Where(d => string.IsNullOrWhiteSpace(filter)
 4993                        || d.StatusCurrent.Name.ToUpper().Contains(filter.ToUpper())
 4994                        || d.Movement.MovementStatus.Name.ToUpper().Contains(filter.ToUpper())
 4995                        || d.Movement.MovementType.Name.ToUpper().Contains(filter.ToUpper()));
 96    }
 97}