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()); }
public void CreateOrder(SellingOrderDto orderDto) { orderDto.CreatedDate = System.DateTime.UtcNow; List <Product> productList = new List <Product>(); foreach (var transaction in orderDto.SellingTransactions) { var product = productRepository.GetBy(transaction.ProductId); product.Quantity -= transaction.Quantity; productList.Add(product); } sellingOrderRepository.Add(orderDto.MappingOrder()); productRepository.UpdateQuantity(productList); }
public void DeleteOrder(SellingOrderDto orderDto) { sellingOrderRepository.Delete(orderDto.MappingOrder()); }