public CustomerDTO AddNewCustomer(CustomerDTO customerDTO) { //check preconditions if (customerDTO == null || customerDTO.CountryId == Guid.Empty) throw new ArgumentException(Messages.warning_CannotAddCustomerWithEmptyInformation); var country = _countryRepository.Get(customerDTO.CountryId); if (country != null) { //Create the entity and the required associated data var address = new Address(customerDTO.AddressCity, customerDTO.AddressZipCode, customerDTO.AddressAddressLine1, customerDTO.AddressAddressLine2); //TODO: usar factory var customer = Customer.CreateCustomer(customerDTO.FirstName, customerDTO.LastName, customerDTO.Telephone, customerDTO.Company, country, address); //save entity SaveCustomer(customer); //return the data with id and assigned default values //return customer.ProjectedAs<CustomerDTO>(); // TODO: fazer codigo de mapeamento ou usar mapper return customerDTO; } else return null; }
///// <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; }