Order CreateNewOrder(OrderDTO dto, Customer associatedCustomer) { //Create a new order entity from factory Order newOrder = Order.CreateOrder(associatedCustomer, dto.ShippingName, dto.ShippingCity, dto.ShippingAddress, dto.ShippingZipCode); //if have lines..add if (dto.OrderLines != null) { foreach (var line in dto.OrderLines) //add order lines newOrder.AddNewOrderLine(line.ProductId, line.Amount, line.UnitPrice, line.Discount / 100); } return newOrder; }
///// <summary> ///// Change the customer credit limit ///// </summary> ///// <param name="newCredit">the new credit limit</param> //public void ChangeTheCurrentCredit(decimal newCredit) //{ // if (IsEnabled) // this.CreditLimit = newCredit; //} public static Customer CreateCustomer(string firstName, string lastName, string telephone, string company, Country country, Address address) { //create new instance and set identity var customer = new Customer(); //set data customer.FirstName = firstName; customer.LastName = lastName; customer.Company = company; customer.Telephone = telephone; //set address customer.Address = address; //TODO: By default this is the limit for customer credit, you can set this //parameter customizable via configuration or other system customer.CreditLimit = 10000; //set the country for this customer customer.SetTheCountryForThisCustomer(country); return customer; }
/// <summary> /// Link a customer to this order line /// </summary> /// <param name="customer">The customer to relate</param> public void SetTheCustomerForThisOrder(Customer customer) { //if (customer == null // || // customer.IsTransient()) //{ // throw new ArgumentException(Messages.exception_CannotAssociateTransientOrNullCustomer); //} this.Customer = customer; this.CustomerId = customer.Id; }
void SaveCustomer(Customer customer) { ////recover validator //var validator = EntityValidatorFactory.CreateValidator(); if (customer.IsValid()) //if customer is valid { //add the customer into the repository _customerRepository.Add(customer); //commit the unit of work //_customerRepository.UnitOfWork.Commit(); } else //customer is not valid, throw validation errors throw new ApplicationValidationErrorsException(customer.GetInvalidMessages()); }
/// <summary> /// Create a new order /// </summary> /// <param name="customer">Associated customer</param> /// <param name="shippingName">The order shipping name</param> /// <param name="shippingCity">The order shipping city</param> /// <param name="shippingAddress">The order shipping address</param> /// <param name="shippingZipCode">The order shipping zip cocde</param> /// <returns>Associated order</returns> public static Order CreateOrder(Customer customer, string shippingName, string shippingCity, string shippingAddress, string shippingZipCode) { //create the order var order = new Order(); //create shipping var shipping = new ShippingInfo(shippingName, shippingAddress, shippingCity, shippingZipCode); //set default values order.OrderDate = DateTime.UtcNow; order.DeliveryDate = null; order.ShippingInformation = shipping; //set customer information order.SetTheCustomerForThisOrder(customer); return order; }