| | | 1 | | using OzonDomains.Models; |
| | | 2 | | using OzonRepositories.Data; |
| | | 3 | | |
| | | 4 | | namespace Services.DataServices |
| | | 5 | | { |
| | | 6 | | public class OrderExtraExpenseDataServices : IDataServices |
| | | 7 | | { |
| | | 8 | | private readonly OrderExtraExpenseRepository _repository; |
| | | 9 | | |
| | 0 | 10 | | public OrderExtraExpenseDataServices(OrderExtraExpenseRepository repository) |
| | | 11 | | { |
| | 0 | 12 | | _repository = repository; |
| | 0 | 13 | | } |
| | | 14 | | |
| | | 15 | | public async Task<int> AddExpense(OrderExtraExpense expense) |
| | | 16 | | { |
| | 0 | 17 | | return await _repository.Add(expense); |
| | 0 | 18 | | } |
| | | 19 | | |
| | | 20 | | public async Task<int> AddExpenses(List<OrderExtraExpense> expenses) |
| | | 21 | | { |
| | 0 | 22 | | return await _repository.AddRange(expenses); |
| | 0 | 23 | | } |
| | | 24 | | |
| | | 25 | | public async Task<int> DeleteExpense(OrderExtraExpense expense) |
| | | 26 | | { |
| | 0 | 27 | | return await _repository.Delete(expense); |
| | 0 | 28 | | } |
| | | 29 | | |
| | | 30 | | public async Task<int> DeleteByOrderId(int orderId) |
| | | 31 | | { |
| | 0 | 32 | | return await _repository.DeleteByOrderId(orderId); |
| | 0 | 33 | | } |
| | | 34 | | |
| | | 35 | | public async Task<List<OrderExtraExpense>> GetExpenses() |
| | | 36 | | { |
| | 0 | 37 | | return await _repository.Get(); |
| | 0 | 38 | | } |
| | | 39 | | |
| | | 40 | | public async Task<OrderExtraExpense?> GetExpenseAsync(int id) |
| | | 41 | | { |
| | 0 | 42 | | return await _repository.GetAsync(id); |
| | 0 | 43 | | } |
| | | 44 | | |
| | | 45 | | public async Task<List<OrderExtraExpense>> GetByOrderId(int orderId) |
| | | 46 | | { |
| | 0 | 47 | | return await _repository.GetByOrderId(orderId); |
| | 0 | 48 | | } |
| | | 49 | | |
| | | 50 | | public async Task<Dictionary<int, List<OrderExtraExpense>>> GetByOrderIds(List<int> orderIds) |
| | | 51 | | { |
| | 0 | 52 | | return await _repository.GetByOrderIds(orderIds); |
| | 0 | 53 | | } |
| | | 54 | | |
| | | 55 | | public async Task<int> UpdateExpense(OrderExtraExpense expense) |
| | | 56 | | { |
| | 0 | 57 | | return await _repository.Update(expense); |
| | 0 | 58 | | } |
| | | 59 | | |
| | | 60 | | /// <summary> |
| | | 61 | | /// Сохранить расходы для заказа (удаляет старые и добавляет новые) |
| | | 62 | | /// </summary> |
| | | 63 | | public async Task<int> SaveExpensesForOrder(int orderId, List<OrderExtraExpense> expenses) |
| | | 64 | | { |
| | | 65 | | // Удаляем старые расходы |
| | 0 | 66 | | await _repository.DeleteByOrderId(orderId); |
| | | 67 | | |
| | | 68 | | // Добавляем новые, если есть |
| | 0 | 69 | | if (expenses != null && expenses.Any()) |
| | | 70 | | { |
| | 0 | 71 | | return await _repository.AddRange(expenses); |
| | | 72 | | } |
| | | 73 | | |
| | 0 | 74 | | return 0; |
| | 0 | 75 | | } |
| | | 76 | | |
| | | 77 | | public async Task<int> SaveChanges() |
| | | 78 | | { |
| | 0 | 79 | | return await _repository.SaveChanges(); |
| | 0 | 80 | | } |
| | | 81 | | } |
| | | 82 | | } |
| | | 83 | | |