| | | 1 | | using Microsoft.EntityFrameworkCore; |
| | | 2 | | using OzonDomains.Models.MatchedRowSys; |
| | | 3 | | using OzonRepositories.Context; |
| | | 4 | | using OzonRepositories.Utils; |
| | | 5 | | using System.Text.Json; |
| | | 6 | | |
| | | 7 | | |
| | | 8 | | namespace OzonRepositories.Data |
| | | 9 | | { |
| | | 10 | | public class MatchedRowRepository : MainRepository, IRepository<MatchedRow> |
| | | 11 | | { |
| | 0 | 12 | | public MatchedRowRepository(ApplicationDbContext orderContext) : base(orderContext) |
| | | 13 | | { |
| | 0 | 14 | | } |
| | | 15 | | |
| | | 16 | | public async Task<int> Add(MatchedRow value) |
| | | 17 | | { |
| | 0 | 18 | | _context.MatchedRows.Add(value); |
| | 0 | 19 | | return await _context.SaveChangesAsync(); |
| | 0 | 20 | | } |
| | | 21 | | |
| | | 22 | | public async Task<int> AddRange(List<MatchedRow> values) |
| | | 23 | | { |
| | 0 | 24 | | return await TransactionHelper.ExecuteInTransactionAsync(_context, async (transaction) => |
| | 0 | 25 | | { |
| | 0 | 26 | | _context.MatchedRows.AddRange(values); |
| | 0 | 27 | | var result = await _context.SaveChangesAsync(); |
| | 0 | 28 | | return result; |
| | 0 | 29 | | }); |
| | 0 | 30 | | } |
| | | 31 | | |
| | | 32 | | |
| | | 33 | | public async Task<int> Delete(MatchedRow value) |
| | | 34 | | { |
| | 0 | 35 | | _context.MatchedRows.Remove(value); |
| | 0 | 36 | | return await _context.SaveChangesAsync(); |
| | 0 | 37 | | } |
| | | 38 | | |
| | | 39 | | public async Task<List<MatchedRow>> Get() |
| | | 40 | | { |
| | 0 | 41 | | return await _context.MatchedRows.ToListAsync(); |
| | 0 | 42 | | } |
| | | 43 | | |
| | | 44 | | public async Task<MatchedRow?> GetAsync(int id) |
| | | 45 | | { |
| | 0 | 46 | | return await _context.MatchedRows.FirstOrDefaultAsync(m => m.Id == id); |
| | 0 | 47 | | } |
| | | 48 | | |
| | | 49 | | public async Task<MatchedRow?> GetAsync(MatchedRow value) |
| | | 50 | | { |
| | 0 | 51 | | var file1DataSerialized = JsonSerializer.Serialize(value.File1Data); |
| | 0 | 52 | | var file2DataSerialized = JsonSerializer.Serialize(value.File2Data); |
| | | 53 | | |
| | 0 | 54 | | return await _context.MatchedRows.FirstOrDefaultAsync(m => |
| | 0 | 55 | | m.File1DataSerialized == file1DataSerialized && |
| | 0 | 56 | | m.File2DataSerialized == file2DataSerialized); |
| | 0 | 57 | | } |
| | | 58 | | |
| | | 59 | | public async Task<int> Update(MatchedRow value) |
| | | 60 | | { |
| | 0 | 61 | | _context.MatchedRows.Update(value); |
| | 0 | 62 | | return await _context.SaveChangesAsync(); |
| | 0 | 63 | | } |
| | | 64 | | } |
| | | 65 | | |
| | | 66 | | } |