< Summary

Information
Class: OzonRepositories.Data.MatchedResultRepository
Assembly: OzonRepositories
File(s): /home/runner/work/Studio2Prod/Studio2Prod/OzonRepositories/Data/MatchedResultRepository.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 59
Coverable lines: 59
Total lines: 115
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 12
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()0%4260%
Delete()0%2040%
Get()100%210%
GetBase()100%210%
GetAsync()100%210%
GetAsync()100%210%
Update()100%210%
UpdateCascade()0%620%

File(s)

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

#LineLine coverage
 1using Microsoft.EntityFrameworkCore;
 2using OzonDomains.Models.MatchedRowSys;
 3using OzonRepositories.Context;
 4
 5namespace OzonRepositories.Data
 6{
 7    public class MatchedResultRepository : MainRepository, IRepository<MatchedResult>
 8    {
 09        public MatchedResultRepository(ApplicationDbContext orderContext) : base(orderContext)
 10        {
 011        }
 12
 13        public async Task<int> Add(MatchedResult value)
 14        {
 015            _context.MatchedResults.Add(value);
 016            return await _context.SaveChangesAsync();
 017        }
 18
 19        public async Task<int> Delete(MatchedResult value)
 20        {
 021            var matchedResult = _context.MatchedResults
 022                                        .Include(m => m.MatchedRows)
 023                                        .Include(m => m.MatchedColumns)
 024                                        .FirstOrDefault(m => m.Id == value.Id);
 25
 026            if (matchedResult != null)
 27            {
 028                if (matchedResult.MatchedRows != null && matchedResult.MatchedRows.Any())
 29                {
 030                    _context.MatchedRows.RemoveRange(matchedResult.MatchedRows);
 31                }
 032                _context.MatchedResults.Remove(matchedResult);
 33            }
 034            return await _context.SaveChangesAsync();
 035        }
 36
 37        public async Task<int> Delete(int id)
 38        {
 039            var valueToDelete = _context.MatchedResults
 040                                        .Include(m => m.MatchedRows)
 041                                        .Include(m => m.MatchedColumns)
 042                                        .FirstOrDefault(v => v.Id == id);
 43
 044            if (valueToDelete != null)
 45            {
 046                if (valueToDelete.MatchedRows != null)
 047                    _context.MatchedRows.RemoveRange(valueToDelete.MatchedRows);
 048                _context.MatchedResults.Remove(valueToDelete);
 049                return await _context.SaveChangesAsync();
 50            }
 51
 052            return 0;
 053        }
 54
 55
 56        public async Task<List<MatchedResult>> Get()
 57        {
 058            return await _context.MatchedResults
 059                .Include(m => m.MatchedRows)
 060                .Include(m => m.MatchedColumns)
 061                .ToListAsync();
 062        }
 63
 64        public async Task<List<MatchedResult>> GetBase()
 65        {
 066            return await _context.MatchedResults.ToListAsync();
 067        }
 68
 69        public async Task<MatchedResult?> GetAsync(int id)
 70        {
 071            return await _context.MatchedResults
 072                .Include(m => m.MatchedRows)
 073                .Include(m => m.MatchedColumns)
 074                .FirstOrDefaultAsync(m => m.Id == id);
 075        }
 76
 77        public async Task<MatchedResult?> GetAsync(MatchedResult value)
 78        {
 079            return await _context.MatchedResults
 080                .Include(m => m.MatchedRows)
 081                .Include(m => m.MatchedColumns)
 082                .FirstOrDefaultAsync(m => m.MainFileName == value.MainFileName && m.ScondaryFileName == value.ScondaryFi
 083        }
 84
 85        public async Task<int> Update(MatchedResult value)
 86        {
 087            _context.MatchedResults.Update(value);
 088            return await _context.SaveChangesAsync();
 089        }
 90
 91        public async Task<int> UpdateCascade(MatchedResult value)
 92        {
 093            var existingMatchedResult = await _context.MatchedResults
 094                .Include(m => m.MatchedRows)
 095                .Include(m => m.MatchedColumns)
 096                .FirstOrDefaultAsync(m => m.Id == value.Id);
 97
 098            if (existingMatchedResult == null)
 99            {
 0100                return -1;
 101            }
 102
 0103            existingMatchedResult.MatchedColumns = value.MatchedColumns;
 0104            existingMatchedResult.MatchedRows = value.MatchedRows;
 0105            existingMatchedResult.ScondaryFileName = value.ScondaryFileName;
 0106            existingMatchedResult.MainFileName = value.MainFileName;
 107
 0108            var saveChangesResult  = _context.SaveChanges();
 109
 0110            return saveChangesResult;
 0111        }
 112
 113
 114    }
 115}