| | | 1 | | using Microsoft.EntityFrameworkCore; |
| | | 2 | | using OzonDomains.Models; |
| | | 3 | | using OzonRepositories.Context; |
| | | 4 | | |
| | | 5 | | namespace OzonRepositories.Data; |
| | | 6 | | |
| | | 7 | | public class OrderHistoryRepository : MainRepository, IOrderHistoryRepository |
| | | 8 | | { |
| | 0 | 9 | | public OrderHistoryRepository(ApplicationDbContext orderContext) : base(orderContext) |
| | | 10 | | { |
| | 0 | 11 | | } |
| | | 12 | | |
| | | 13 | | public async Task<int> Add(OrderHistory value) |
| | | 14 | | { |
| | 0 | 15 | | _context.OrderHistories.Add(value); |
| | 0 | 16 | | return await _context.SaveChangesAsync(); |
| | 0 | 17 | | } |
| | | 18 | | |
| | | 19 | | public async Task<int> Delete(OrderHistory value) |
| | | 20 | | { |
| | 0 | 21 | | _context.OrderHistories.Remove(value); |
| | 0 | 22 | | return await _context.SaveChangesAsync(); |
| | 0 | 23 | | } |
| | | 24 | | |
| | | 25 | | public Task<List<OrderHistory>> Get() |
| | | 26 | | { |
| | 0 | 27 | | return _context.OrderHistories |
| | 0 | 28 | | .Include(oh => oh.Order) |
| | 0 | 29 | | .OrderByDescending(oh => oh.ChangedAt) |
| | 0 | 30 | | .ToListAsync(); |
| | | 31 | | } |
| | | 32 | | |
| | | 33 | | public async Task<OrderHistory?> GetAsync(int id) |
| | | 34 | | { |
| | 0 | 35 | | return await _context.OrderHistories |
| | 0 | 36 | | .Include(oh => oh.Order) |
| | 0 | 37 | | .FirstOrDefaultAsync(oh => oh.Id == id); |
| | 0 | 38 | | } |
| | | 39 | | |
| | | 40 | | public async Task<OrderHistory?> GetAsync(OrderHistory value) |
| | | 41 | | { |
| | 0 | 42 | | return await _context.OrderHistories |
| | 0 | 43 | | .FirstOrDefaultAsync(oh => oh.OrderId == value.OrderId && |
| | 0 | 44 | | oh.ColumnName == value.ColumnName && |
| | 0 | 45 | | oh.ChangedAt == value.ChangedAt); |
| | 0 | 46 | | } |
| | | 47 | | |
| | | 48 | | public async Task<int> Update(OrderHistory value) |
| | | 49 | | { |
| | 0 | 50 | | _context.OrderHistories.Update(value); |
| | 0 | 51 | | return await _context.SaveChangesAsync(); |
| | 0 | 52 | | } |
| | | 53 | | |
| | | 54 | | public async Task<List<OrderHistory>> GetByOrderIdAsync(int orderId) |
| | | 55 | | { |
| | 0 | 56 | | return await _context.OrderHistories |
| | 0 | 57 | | .Where(oh => oh.OrderId == orderId) |
| | 0 | 58 | | .Include(oh => oh.Order!) |
| | 0 | 59 | | .ThenInclude(c => c.OzonClient) |
| | 0 | 60 | | .Include(oh => oh.Order!) |
| | 0 | 61 | | .ThenInclude(o => o.ProductInfo) |
| | 0 | 62 | | .OrderByDescending(oh => oh.ChangedAt) |
| | 0 | 63 | | .ToListAsync(); |
| | 0 | 64 | | } |
| | | 65 | | |
| | | 66 | | public async Task<List<OrderHistory>> GetRecentChangesAsync(int count = 50) |
| | | 67 | | { |
| | 0 | 68 | | return await _context.OrderHistories |
| | 0 | 69 | | .OrderByDescending(oh => oh.ChangedAt) |
| | 0 | 70 | | .Take(count) |
| | 0 | 71 | | .ToListAsync(); |
| | 0 | 72 | | } |
| | | 73 | | |
| | | 74 | | public async Task<List<OrderHistory>> GetChangesAfterDateAsync(DateTime afterDate) |
| | | 75 | | { |
| | 0 | 76 | | return await _context.OrderHistories |
| | 0 | 77 | | .Where(oh => oh.ChangedAt > afterDate) |
| | 0 | 78 | | .OrderByDescending(oh => oh.ChangedAt) |
| | 0 | 79 | | .ToListAsync(); |
| | 0 | 80 | | } |
| | | 81 | | |
| | | 82 | | |
| | | 83 | | } |