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); }
public static CustomerOrder MakeCustomerOrder(int registerNumber, Customer customer) { if (registerNumber <= 0) { throw new ArgumentException("Register number must be larger than 0."); } if (customer == null) { throw new ArgumentNullException("Customer must have a value."); } var customerOrder = new CustomerOrder(); customerOrder.RegisterDate = DateTime.Now; customerOrder.RegisterNumber = registerNumber; customerOrder.CustomerId = customer.Id; customerOrder.Customer = customer; customerOrder.TotalValue = 0; customerOrder.CustomerOrderItems = new List <CustomerOrderItem>(); return(customerOrder); }