< Summary

Information
Class: OzonRepositories.Data.Bitrix.PriceHistoryRepository
Assembly: OzonRepositories
File(s): /home/runner/work/Studio2Prod/Studio2Prod/OzonRepositories/Data/Bitrix/PriceHistoryRepository.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 42
Coverable lines: 42
Total lines: 85
Line coverage: 0%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
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%
GetAsync()100%210%
GetAsync()100%210%
GetByArticleAsync()100%210%
GetByBitrixIdAsync()100%210%
GetLastByBitrixIdAsync()100%210%
GetLastByBitrixIdsAsync()100%210%
GetLastRecordsAsync()100%210%
Update()100%210%

File(s)

/home/runner/work/Studio2Prod/Studio2Prod/OzonRepositories/Data/Bitrix/PriceHistoryRepository.cs

#LineLine coverage
 1using Microsoft.EntityFrameworkCore;
 2using OzonRepositories.Context;
 3
 4namespace OzonRepositories.Data.Bitrix;
 5
 6public class PriceHistoryRepository : MainRepository, IRepository<PriceHistory>
 7{
 08    public PriceHistoryRepository(ApplicationDbContext orderContext) : base(orderContext)
 9    {
 010    }
 11
 12    public async Task<int> Add(PriceHistory value)
 13    {
 014        _context.PriceHistories.Add(value);
 015        return await _context.SaveChangesAsync();
 016    }
 17
 18    public async Task<int> Delete(PriceHistory value)
 19    {
 020        _context.PriceHistories.Remove(value);
 021        return await _context.SaveChangesAsync();
 022    }
 23
 24    public Task<List<PriceHistory>> Get()
 25    {
 026        return _context.PriceHistories.ToListAsync();
 27    }
 28
 29    public async Task<PriceHistory?> GetAsync(int id)
 30    {
 031        return await _context.PriceHistories.FirstOrDefaultAsync(c => c.Id == id);
 032    }
 33
 34    public async Task<PriceHistory?> GetAsync(PriceHistory value)
 35    {
 036        return await _context.PriceHistories.FirstOrDefaultAsync(c => c.Article == value.Article);
 037    }
 38
 39    public async Task<List<PriceHistory>> GetByArticleAsync(string article)
 40    {
 041        return await _context.PriceHistories
 042            .Where(ph => ph.Article == article)
 043            .OrderByDescending(ph => ph.CreateDateTime)
 044            .ToListAsync();
 045    }
 46
 47    public async Task<List<PriceHistory>> GetByBitrixIdAsync(int bitrixId)
 48    {
 049        return await _context.PriceHistories
 050            .Where(ph => ph.BitrixId == bitrixId)
 051            .OrderByDescending(ph => ph.CreateDateTime)
 052            .ToListAsync();
 053    }
 54
 55    public async Task<PriceHistory?> GetLastByBitrixIdAsync(int bitrixId)
 56    {
 057        return await _context.PriceHistories
 058            .Where(ph => ph.BitrixId == bitrixId)
 059            .OrderByDescending(ph => ph.CreateDateTime)
 060            .FirstOrDefaultAsync();
 061    }
 62
 63    public async Task<Dictionary<int, PriceHistory>> GetLastByBitrixIdsAsync(List<int> bitrixIds)
 64    {
 065        return await _context.PriceHistories
 066            .Where(ph => bitrixIds.Contains(ph.BitrixId))
 067            .GroupBy(ph => ph.BitrixId)
 068            .Select(g => g.OrderByDescending(ph => ph.CreateDateTime).First())
 069            .ToDictionaryAsync(ph => ph.BitrixId, ph => ph);
 070    }
 71
 72    public async Task<List<PriceHistory>> GetLastRecordsAsync(int count)
 73    {
 074        return await _context.PriceHistories
 075            .OrderByDescending(ph => ph.CreateDateTime)
 076            .Take(count)
 077            .ToListAsync();
 078    }
 79
 80    public async Task<int> Update(PriceHistory value)
 81    {
 082        _context.PriceHistories.Update(value);
 083        return await _context.SaveChangesAsync();
 084    }
 85}