< Summary

Information
Class: OzonRepositories.Data.Bitrix.BitrixRepository
Assembly: OzonRepositories
File(s): /home/runner/work/Studio2Prod/Studio2Prod/OzonRepositories/Data/Bitrix/BitrixRepository.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 32
Coverable lines: 32
Total lines: 112
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 8
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%
GetBIblockElementPropertiesByArticle(...)100%210%
GetBCatalogPriceByIblockElementId()0%620%
GetBCatalogStoreProductsByProductId()0%620%
GetBCatalogStoreById()0%620%
GetBCatalogGroupById()0%620%

File(s)

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

#LineLine coverage
 1using Microsoft.EntityFrameworkCore;
 2using OzonDomains.Models.BitrixModels;
 3using OzonRepositories.Context;
 4using OzonRepositories.Services;
 5using System.Data;
 6
 7namespace OzonRepositories.Data.Bitrix;
 8
 9public class BitrixRepository : IBitrixRepository
 10{
 11    private readonly BitrixContext _context;
 12    private readonly IBitrixConnectionService _connectionService;
 13
 014    public BitrixRepository(BitrixContext context, IBitrixConnectionService connectionService)
 15    {
 016        _context = context;
 017        _connectionService = connectionService;
 018    }
 19
 20    public List<BIblockElementProperty> GetBIblockElementPropertiesByArticle(string article)
 21    {
 22        try
 23        {
 024            return _context.BIblockElementProperties.Where(pr => pr.Value==article && pr.Description == "Артикул").ToLis
 25        }
 026        catch
 27        {
 28            // При ошибке возвращаем пустой список вместо падения страницы
 029            return new List<BIblockElementProperty>();
 30        }
 031    }
 32
 33    public async Task<BCatalogPrice?> GetBCatalogPriceByIblockElementId(int iblockElementId)
 34    {
 35        // Проверяем доступность соединения с Bitrix (с кэшированием)
 036        if (!await _connectionService.IsConnectionAvailableAsync())
 37        {
 38            // Возвращаем null вместо падения страницы
 039            return null;
 40        }
 41
 42        try
 43        {
 044            return await _context.BCatalogPrices.FirstOrDefaultAsync(pr => pr.ProductId == iblockElementId);
 45        }
 046        catch
 47        {
 48            // При ошибке возвращаем null вместо падения страницы
 049            return null;
 50        }
 051    }
 52
 53    public async Task<List<BCatalogStoreProduct>> GetBCatalogStoreProductsByProductId(int productId)
 54    {
 55        // Проверяем доступность соединения с Bitrix (с кэшированием)
 056        if (!await _connectionService.IsConnectionAvailableAsync())
 57        {
 58            // Возвращаем пустой список вместо падения страницы
 059            return new List<BCatalogStoreProduct>();
 60        }
 61
 62        try
 63        {
 064            return await _context.BCatalogStoreProducts.Where(pr => pr.ProductId == productId && pr.Amount != 0).ToListA
 65        }
 066        catch
 67        {
 68            // При ошибке возвращаем пустой список вместо падения страницы
 069            return new List<BCatalogStoreProduct>();
 70        }
 071    }
 72
 73    public async Task<BCatalogStore?> GetBCatalogStoreById(int id)
 74    {
 75        // Проверяем доступность соединения с Bitrix (с кэшированием)
 076        if (!await _connectionService.IsConnectionAvailableAsync())
 77        {
 78            // Возвращаем null вместо падения страницы
 079            return null;
 80        }
 81
 82        try
 83        {
 084            return await _context.BCatalogStores.FindAsync(id);
 85        }
 086        catch
 87        {
 88            // При ошибке возвращаем null вместо падения страницы
 089            return null;
 90        }
 091    }
 92
 93    public async Task<BCatalogGroup?> GetBCatalogGroupById(int id)
 94    {
 95        // Проверяем доступность соединения с Bitrix (с кэшированием)
 096        if (!await _connectionService.IsConnectionAvailableAsync())
 97        {
 98            // Возвращаем null вместо падения страницы
 099            return null;
 100        }
 101
 102        try
 103        {
 0104            return await _context.BCatalogGroups.FindAsync(id);
 105        }
 0106        catch
 107        {
 108            // При ошибке возвращаем null вместо падения страницы
 0109            return null;
 110        }
 0111    }
 112}