< Summary

Information
Class: OzonRepositories.Data.ExcludedArticleRepository
Assembly: OzonRepositories
File(s): /home/runner/work/Studio2Prod/Studio2Prod/OzonRepositories/Data/ExcludedArticleRepository.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 53
Coverable lines: 53
Total lines: 98
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 6
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%
Add()100%210%
Delete()100%210%
Get()100%210%
GetPaged(...)100%210%
GetTotalCount()100%210%
GetAsync()100%210%
GetAsync()100%210%
Update()100%210%
GetFilteredOrdersAsync()0%620%

File(s)

/home/runner/work/Studio2Prod/Studio2Prod/OzonRepositories/Data/ExcludedArticleRepository.cs

#LineLine coverage
 1using Microsoft.EntityFrameworkCore;
 2using OzonDomains.Models;
 3using OzonRepositories.Context;
 4
 5namespace OzonRepositories.Data
 6{
 7    public class ExcludedArticleRepository : MainRepository, IRepository<ExcludedArticle>
 8    {
 09        public ExcludedArticleRepository(ApplicationDbContext orderContext) : base(orderContext)
 10        {
 011        }
 12
 13        public async Task<int> Add(ExcludedArticle value)
 14        {
 015            _context.ExcludedArticles.Add(value);
 016            return await _context.SaveChangesAsync();
 017        }
 18
 19        public async Task<int> Delete(ExcludedArticle value)
 20        {
 021            _context.ExcludedArticles.Remove(value);
 022            return await _context.SaveChangesAsync();
 023        }
 24
 25        public Task<List<ExcludedArticle>> Get()
 26        {
 027            return _context.ExcludedArticles
 028                .Include(e => e.OzonClient)
 029                .OrderByDescending(e => e.Id)
 030                .ToListAsync();
 31        }
 32
 33        public Task<List<ExcludedArticle>> GetPaged(int page = 1, int pageSize = 20)
 34        {
 035            return _context.ExcludedArticles
 036                .Include(e => e.OzonClient)
 037                .OrderByDescending(e => e.Id)
 038                .Skip((page - 1) * pageSize)
 039                .Take(pageSize)
 040                .ToListAsync();
 41        }
 42
 43        public Task<int> GetTotalCount()
 44        {
 045            return _context.ExcludedArticles.CountAsync();
 46        }
 47
 48        public async Task<ExcludedArticle?> GetAsync(int id)
 49        {
 050            return await _context.ExcludedArticles
 051                .Include(e => e.OzonClient)
 052                .FirstOrDefaultAsync(e => e.Id == id);
 053        }
 54
 55        public async Task<ExcludedArticle?> GetAsync(ExcludedArticle value)
 56        {
 057            return await _context.ExcludedArticles
 058                .Include(e => e.OzonClient)
 059                .FirstOrDefaultAsync(e => e.Article == value.Article
 060                                          && e.OzonClientId == value.OzonClientId);
 061        }
 62
 63        public async Task<int> Update(ExcludedArticle value)
 64        {
 065            _context.ExcludedArticles.Update(value);
 066            return await _context.SaveChangesAsync();
 067        }
 68
 69        public async Task<List<Order>> GetFilteredOrdersAsync(List<Order> orders)
 70        {
 071            if (orders.Count == 0)
 072                return orders;
 73
 074            var clientNames = orders
 075                .Where(o => o.OzonClient != null)
 076                .Select(o => o.OzonClient!.Name)
 077                .Distinct()
 078                .ToList();
 79
 080            var articles = orders
 081                .Select(o => o.Article)
 082                .Distinct()
 083                .ToList();
 84
 085            var excluded = await _context.ExcludedArticles
 086                .Include(e => e.OzonClient)
 087                .Where(e => clientNames.Contains(e.OzonClient.Name) && articles.Contains(e.Article))
 088                .Select(e => new { ClientName = e.OzonClient.Name, e.Article })
 089                .ToListAsync();
 90
 091            return orders
 092                .Where(o => !excluded.Any(e =>
 093                    e.ClientName == o.OzonClient?.Name &&
 094                    e.Article == o.Article))
 095                .ToList();
 096        }
 97    }
 98}