< Summary

Information
Class: ExcelMappingRepository
Assembly: OzonRepositories
File(s): /home/runner/work/Studio2Prod/Studio2Prod/OzonRepositories/Data/ExcelMapping/ExcelMappingRepository.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 38
Coverable lines: 38
Total lines: 72
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%
GetByIdAsync()100%210%
GetAllAsync()100%210%
CreateAsync()100%210%
UpdateAsync()100%210%
DeleteAsync()0%620%
GetRequestByIdAsync()0%2040%

File(s)

/home/runner/work/Studio2Prod/Studio2Prod/OzonRepositories/Data/ExcelMapping/ExcelMappingRepository.cs

#LineLine coverage
 1
 2using System.Text.Json;
 3using Microsoft.EntityFrameworkCore;
 4using OzonDomains;
 5using OzonOrdersWeb.Areas.OzonCards.ViewModels;
 6using OzonRepositories.Context;
 7
 8public class ExcelMappingRepository : IExcelMappingRepository
 9{
 10        private readonly ApplicationDbContext _context;
 11
 012        public ExcelMappingRepository(ApplicationDbContext context)
 13        {
 014            _context = context;
 015        }
 16
 17        public async Task<ExcelMapping?> GetByIdAsync(int id)
 18        {
 019            return await _context.ExcelMappings.FindAsync(id);
 020        }
 21
 22        public async Task<List<ExcelMapping>> GetAllAsync()
 23        {
 024            return await _context.ExcelMappings
 025                .OrderByDescending(x => x.CreatedDate)
 026                .ToListAsync();
 027        }
 28
 29        public async Task<int> CreateAsync(ExcelMapping mapping)
 30        {
 031            _context.ExcelMappings.Add(mapping);
 032            await _context.SaveChangesAsync();
 033            return mapping.Id;
 034        }
 35
 36        public async Task UpdateAsync(ExcelMapping mapping)
 37        {
 038            mapping.ModifiedDate = DateTime.UtcNow;
 039            _context.ExcelMappings.Update(mapping);
 040            await _context.SaveChangesAsync();
 041        }
 42
 43        public async Task DeleteAsync(int id)
 44        {
 045            var mapping = await GetByIdAsync(id);
 046            if (mapping != null)
 47            {
 048                _context.ExcelMappings.Remove(mapping);
 049                await _context.SaveChangesAsync();
 50            }
 051        }
 52
 53        public async Task<ExcelMappingRequest?> GetRequestByIdAsync(int id)
 54        {
 055            var mapping = await GetByIdAsync(id);
 056            if (mapping == null)
 057                return null;
 58
 059            return new ExcelMappingRequest
 060            {
 061                SourceFileName = mapping.SourceFileName,
 062                DestinationFileName = mapping.DestinationFileName,
 063                SourceSheet = mapping.SourceSheet,
 064                DestinationSheet = mapping.DestinationSheet,
 065                SourceHeaderRow = mapping.SourceHeaderRow,
 066                DestinationHeaderRow = mapping.DestinationHeaderRow,
 067                SourceDataStartRow = mapping.SourceDataStartRow,
 068                DestinationDataStartRow = mapping.DestinationDataStartRow,
 069                ColumnMappings = JsonSerializer.Deserialize<List<ColumnMappingExcel>>(mapping.ColumnMappingsJson) ?? new
 070            };
 071        }
 72}