< Summary

Information
Class: OzonRepositories.Data.WarehouseMappingRepository
Assembly: OzonRepositories
File(s): /home/runner/work/Studio2Prod/Studio2Prod/OzonRepositories/Data/WarehouseMappingRepository.cs
Line coverage
35%
Covered lines: 43
Uncovered lines: 77
Coverable lines: 120
Total lines: 199
Line coverage: 35.8%
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%11100%
Add()100%11100%
Delete()100%11100%
Get()100%11100%
GetAsync()100%210%
GetAsync()100%210%
GetByOzonName()100%210%
GetByOzonNameAndClient()100%210%
GetByOzonNamesAndClient()100%210%
GetListByBitrixName()100%210%
GetByNamByClient()100%210%
GetByClientIdAsync()100%11100%
GetExactAsync()100%11100%
Update()100%11100%
GetByBitrixNamesAndClient()100%210%
GetOzonWarehouseNamesByClient()100%210%

File(s)

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

#LineLine coverage
 1using Microsoft.EntityFrameworkCore;
 2using Microsoft.Extensions.DependencyInjection;
 3using OzonDomains.Models;
 4using OzonRepositories.Context;
 5
 6namespace OzonRepositories.Data;
 7
 8public class WarehouseMappingRepository : MainRepository, IRepository<WarehouseMapping>
 9{
 10    private readonly IServiceScopeFactory _scopeFactory;
 11
 12    public WarehouseMappingRepository(ApplicationDbContext orderContext, IServiceScopeFactory scopeFactory)
 2913        : base(orderContext)
 14    {
 2915        _scopeFactory = scopeFactory;
 2916    }
 17
 18    public async Task<int> Add(WarehouseMapping value)
 19    {
 620        using var scope = _scopeFactory.CreateScope();
 621        var context = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
 22
 623        context.WarehouseMappings.Add(value);
 624        return await context.SaveChangesAsync();
 625    }
 26
 27    public async Task<int> Delete(WarehouseMapping value)
 28    {
 129        using var scope = _scopeFactory.CreateScope();
 130        var context = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
 31
 132        context.WarehouseMappings.Remove(value);
 133        return await context.SaveChangesAsync();
 134    }
 35
 36    public async Task<List<WarehouseMapping>> Get()
 37    {
 1438        using var scope = _scopeFactory.CreateScope();
 1439        var context = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
 40
 1441        return await context.WarehouseMappings
 1442            .Include(wm => wm.OzonClient)
 1443            .Include(wm => wm.Supplier)
 1444            .ToListAsync();
 1445    }
 46
 47    public async Task<WarehouseMapping?> GetAsync(int id)
 48    {
 049        using var scope = _scopeFactory.CreateScope();
 050        var context = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
 51
 052        return await context.WarehouseMappings
 053            .Include(wm => wm.OzonClient)
 054            .Include(wm => wm.Supplier)
 055            .FirstOrDefaultAsync(c => c.Id == id);
 056    }
 57
 58    public async Task<WarehouseMapping?> GetAsync(WarehouseMapping value)
 59    {
 060        using var scope = _scopeFactory.CreateScope();
 061        var context = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
 62
 063        return await context.WarehouseMappings
 064            .Include(wm => wm.OzonClient)
 065            .Include(wm => wm.Supplier)
 066            .FirstOrDefaultAsync(c =>
 067                c.BitrixWarehouseName == value.BitrixWarehouseName &&
 068                c.OzonWarehouseName == value.OzonWarehouseName &&
 069                c.OzonClientId == value.OzonClientId);
 070    }
 71
 72    public async Task<WarehouseMapping?> GetByOzonName(string ozonName)
 73    {
 074        using var scope = _scopeFactory.CreateScope();
 075        var context = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
 76
 077        return await context.WarehouseMappings
 078            .Include(wm => wm.Supplier)
 079            .FirstOrDefaultAsync(w => w.OzonWarehouseName == ozonName);
 080    }
 81
 82    public async Task<List<string>> GetByOzonNameAndClient(string ozonName, string clientName)
 83    {
 084        using var scope = _scopeFactory.CreateScope();
 085        var context = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
 86
 087        return await context.WarehouseMappings
 088            .Include(o => o.OzonClient)
 089            .Include(wm => wm.Supplier)
 090            .Where(w => w.OzonWarehouseName == ozonName
 091                        && w.OzonClient != null && w.OzonClient.Name == clientName)
 092            .Select(m => m.BitrixWarehouseName)
 093            .ToListAsync();
 094    }
 95
 96    // Новый метод для получения всех маппингов по нескольким Ozon названиям и клиенту
 97    public async Task<List<WarehouseMapping>> GetByOzonNamesAndClient(List<string> ozonNames, string clientName)
 98    {
 099        using var scope = _scopeFactory.CreateScope();
 0100        var context = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
 101
 0102        return await context.WarehouseMappings
 0103            .Include(o => o.OzonClient)
 0104            .Include(wm => wm.Supplier)
 0105            .Where(w => ozonNames.Contains(w.OzonWarehouseName)
 0106                        && w.OzonClient != null && w.OzonClient.Name == clientName)
 0107            .ToListAsync();
 0108    }
 109
 110    public async Task<List<WarehouseMapping>> GetListByBitrixName(string bitrixName)
 111    {
 0112        using var scope = _scopeFactory.CreateScope();
 0113        var context = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
 114
 0115        return await context.WarehouseMappings
 0116            .Include(wm => wm.Supplier)
 0117            .Where(w => w.BitrixWarehouseName == bitrixName)
 0118            .ToListAsync();
 0119    }
 120
 121    public async Task<List<string>> GetByNamByClient(OzonClient client, List<string> warehouses)
 122    {
 0123        using var scope = _scopeFactory.CreateScope();
 0124        var context = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
 125
 0126        return await context.WarehouseMappings
 0127            .Include(wm => wm.Supplier)
 0128            .Where(w => w.OzonClientId == client.Id)
 0129            .Where(w => warehouses.Contains(w.BitrixWarehouseName))
 0130            .Select(w => w.OzonWarehouseName)
 0131            .ToListAsync();
 0132    }
 133
 134    // Новый метод для поиска по ID клиента
 135    public async Task<List<WarehouseMapping>> GetByClientIdAsync(int clientId)
 136    {
 34137        using var scope = _scopeFactory.CreateScope();
 34138        var context = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
 139
 34140        return await context.WarehouseMappings
 34141            .Include(wm => wm.OzonClient)
 34142            .Include(wm => wm.Supplier)
 34143            .Where(wm => wm.OzonClientId == clientId)
 34144            .ToListAsync();
 34145    }
 146
 147    // Новый метод для поиска конкретного сопоставления по всем параметрам
 148    public async Task<WarehouseMapping?> GetExactAsync(string bitrixName, string ozonName, int clientId)
 149    {
 5150        using var scope = _scopeFactory.CreateScope();
 5151        var context = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
 152
 5153        return await context.WarehouseMappings
 5154            .Include(wm => wm.OzonClient)
 5155            .Include(wm => wm.Supplier)
 5156            .FirstOrDefaultAsync(c =>
 5157                c.BitrixWarehouseName == bitrixName &&
 5158                c.OzonWarehouseName == ozonName &&
 5159                c.OzonClientId == clientId);
 5160    }
 161
 162    public async Task<int> Update(WarehouseMapping value)
 163    {
 7164        using var scope = _scopeFactory.CreateScope();
 7165        var context = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
 166
 7167        context.WarehouseMappings.Update(value);
 7168        return await context.SaveChangesAsync();
 7169    }
 170
 171    // Новый метод для массового получения маппингов по Bitrix названиям и клиенту
 172    public async Task<List<WarehouseMapping>> GetByBitrixNamesAndClient(List<string> bitrixNames, string clientName)
 173    {
 0174        using var scope = _scopeFactory.CreateScope();
 0175        var context = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
 176
 0177        return await context.WarehouseMappings
 0178            .Include(o => o.OzonClient)
 0179            .Include(wm => wm.Supplier)
 0180            .Where(w => bitrixNames.Contains(w.BitrixWarehouseName)
 0181                        && w.OzonClient != null && w.OzonClient.Name == clientName)
 0182            .ToListAsync();
 0183    }
 184
 185    // Новый метод для получения всех уникальных Ozon названий складов для клиента
 186    public async Task<List<string>> GetOzonWarehouseNamesByClient(string clientName)
 187    {
 0188        using var scope = _scopeFactory.CreateScope();
 0189        var context = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
 190
 0191        return await context.WarehouseMappings
 0192            .Include(o => o.OzonClient)
 0193            .Include(wm => wm.Supplier)
 0194            .Where(w => w.OzonClient != null && w.OzonClient.Name == clientName)
 0195            .Select(w => w.OzonWarehouseName)
 0196            .Distinct()
 0197            .ToListAsync();
 0198    }
 199}