| | | 1 | | using Microsoft.EntityFrameworkCore; |
| | | 2 | | using OzonDomains.Models; |
| | | 3 | | using OzonRepositories.Context; |
| | | 4 | | |
| | | 5 | | namespace OzonRepositories.Data |
| | | 6 | | { |
| | | 7 | | public class OrderArchiveRepository : MainRepository, IRepository<OrderArchive> |
| | | 8 | | { |
| | 15 | 9 | | public OrderArchiveRepository(ApplicationDbContext orderContext) : base(orderContext) |
| | | 10 | | { |
| | 15 | 11 | | } |
| | | 12 | | |
| | | 13 | | public async Task<int> Add(OrderArchive value) |
| | | 14 | | { |
| | 6 | 15 | | _context.OrderArchives.Add(value); |
| | 6 | 16 | | return await _context.SaveChangesAsync(); |
| | 6 | 17 | | } |
| | | 18 | | |
| | | 19 | | public async Task<int> Delete(OrderArchive value) |
| | | 20 | | { |
| | 2 | 21 | | _context.OrderArchives.Remove(value); |
| | 2 | 22 | | return await _context.SaveChangesAsync(); |
| | 2 | 23 | | } |
| | | 24 | | |
| | | 25 | | public Task<List<OrderArchive>> Get() |
| | | 26 | | { |
| | 1 | 27 | | return _context.OrderArchives |
| | 1 | 28 | | .Include(oa => oa.Order) |
| | 1 | 29 | | .ToListAsync(); |
| | | 30 | | } |
| | | 31 | | |
| | | 32 | | public async Task<OrderArchive?> GetAsync(int id) |
| | | 33 | | { |
| | 2 | 34 | | return await _context.OrderArchives |
| | 2 | 35 | | .FirstOrDefaultAsync(oa => oa.Id == id); |
| | 2 | 36 | | } |
| | | 37 | | |
| | | 38 | | public async Task<OrderArchive?> GetAsync(OrderArchive value) |
| | | 39 | | { |
| | 2 | 40 | | return await _context.OrderArchives |
| | 2 | 41 | | .FirstOrDefaultAsync(oa => oa.OrderId == value.OrderId); |
| | 2 | 42 | | } |
| | | 43 | | |
| | | 44 | | public async Task<int> Update(OrderArchive value) |
| | | 45 | | { |
| | 1 | 46 | | _context.OrderArchives.Update(value); |
| | 1 | 47 | | return await _context.SaveChangesAsync(); |
| | 1 | 48 | | } |
| | | 49 | | |
| | | 50 | | public async Task<OrderArchive?> GetByOrderIdAsync(int orderId) |
| | | 51 | | { |
| | 9 | 52 | | return await _context.OrderArchives |
| | 9 | 53 | | .FirstOrDefaultAsync(oa => oa.OrderId == orderId); |
| | 9 | 54 | | } |
| | | 55 | | |
| | | 56 | | public async Task<bool> IsOrderArchivedAsync(int orderId) |
| | | 57 | | { |
| | 5 | 58 | | return await _context.OrderArchives |
| | 5 | 59 | | .AnyAsync(oa => oa.OrderId == orderId); |
| | 5 | 60 | | } |
| | | 61 | | |
| | | 62 | | public async Task<List<OrderArchive>> GetArchivedOrdersWithDetailsAsync() |
| | | 63 | | { |
| | 2 | 64 | | return await _context.OrderArchives |
| | 2 | 65 | | .Include(oa => oa.Order) |
| | 2 | 66 | | .ThenInclude(o => o.AppStatus) |
| | 2 | 67 | | .Include(oa => oa.Order) |
| | 2 | 68 | | .ThenInclude(o => o.OzonClient) |
| | 2 | 69 | | .Include(oa => oa.Order) |
| | 2 | 70 | | .ThenInclude(o => o.ProductInfo) |
| | 2 | 71 | | .OrderByDescending(oa => oa.ArchivedAt) |
| | 2 | 72 | | .ToListAsync(); |
| | 2 | 73 | | } |
| | | 74 | | } |
| | | 75 | | } |