public SellingOrderDto UpdateSellingOrder(SellingOrderDto orderDto) { var order = _mapper.Map <SellingOrder>(orderDto); int res = _orderRepo.Update(order); if (res <= 0) { return(null); } return(orderDto); }
public void UpdateOrder(SellingOrderDto orderDto) { var oldOrder = sellingOrderRepository.GetBy(orderDto.Id); oldOrder.SellingTransactions = sellingTransactionRepository.GetTransactions(orderDto.Id).ToList(); /*Remove old quantity*/ List <Product> productList = new List <Product>(); foreach (var transaction in oldOrder.SellingTransactions) { var product = productRepository.GetBy(transaction.ProductId); product.Quantity += transaction.Quantity; productList.Add(product); } productRepository.UpdateQuantity(productList); /*Remove old transaction*/ sellingTransactionRepository.RemoveRange(oldOrder.SellingTransactions); /*Add new quantity*/ List <Product> newProductList = new List <Product>(); foreach (var transaction in orderDto.SellingTransactions) { transaction.SellingOrderId = orderDto.Id; var product = productRepository.GetBy(transaction.ProductId); product.Quantity -= transaction.Quantity; newProductList.Add(product); } productRepository.UpdateQuantity(newProductList); /*Add new transaction*/ sellingOrderRepository.Update(orderDto.MappingOrder()); }