public static CustomerDeposit MakeCustomerDeposit(CustomerOrderItem customerOrderItem, float amount, DepositMovement depositMovement) { if (customerOrderItem == null) { throw new ArgumentNullException("Customer order item must have a value."); } if (amount <= 0) { throw new ArgumentException("Amount must be larger than 0."); } var deposit = new CustomerDeposit(); deposit.Amount = amount; deposit.RegisterDate = DateTime.Now; deposit.MovementType = depositMovement; deposit.CustomerOrderItemId = customerOrderItem.Id; deposit.CustomerOrderItem = customerOrderItem; deposit.Sku = customerOrderItem.Product.Sku; deposit.CustomerOrderItem.Product.UpdateAmount(depositMovement == DepositMovement.In ? amount : -amount); return(deposit); }
public CustomerOrderItem AddItem(Product product, float amount) { if (IsDeleted) { throw new InvalidOperationException("Order is deleted."); } var customerOrderItem = CustomerOrderItem.MakeCustomerOrderItem(this, product, amount); CustomerOrderItems.Add(customerOrderItem); return(customerOrderItem); }
public static CustomerOrderItem MakeCustomerOrderItem(CustomerOrder customerOrder, Product product, float amount) { if (customerOrder == null) { throw new ArgumentNullException("Customer order must have a value."); } if (product == null) { throw new ArgumentNullException("Product must have a value."); } if (amount <= 0) { throw new ArgumentException("Amount must be larger than 0."); } if (product.Amount < amount) { throw new ArgumentException("Amount larger than product deposit."); } var customerOrderItem = new CustomerOrderItem(); customerOrderItem.CustomerOrderId = customerOrder.Id; customerOrderItem.CustomerOrder = customerOrder; customerOrderItem.ProductId = product.Id; customerOrderItem.Product = product; customerOrderItem.Amount = amount; customerOrderItem.Price = product.Price; customerOrderItem.TotalValue = customerOrderItem.Price * customerOrderItem.Amount; customerOrderItem.Deposits = new List <CustomerDeposit>(); customerOrder.UpdateTotalValue(customerOrderItem.TotalValue); var deposit = CustomerDeposit.MakeCustomerDeposit(customerOrderItem, amount, DepositMovement.Out); customerOrderItem.Deposits.Add(deposit); return(customerOrderItem); }