/// <summary> /// The add address. /// </summary> /// <param name="address"> /// The address. /// </param> public void AddAddress(Address address) { var dalAddress = new DataAccessLayer.Address(); var dalCustomerAddress = new CustomerAddress(); BusinessObjectLayer.Customer customer = this.User; var customerAddress = new BusinessObjectLayer.CustomerAddress(); dalAddress.Insert(address); customerAddress.CustomerId = customer.Id; customerAddress.AddressId = address.Id; dalCustomerAddress.Insert(customerAddress); }
/// <summary> /// The register. /// </summary> /// <param name="email"> /// The email. /// </param> /// <param name="password"> /// The password. /// </param> /// <param name="phone"> /// The phone. /// </param> /// <param name="cellPhone"> /// The cell phone. /// </param> /// <param name="firstName"> /// The first name. /// </param> /// <param name="lastName"> /// The last name. /// </param> /// <param name="companyName"> /// The company name. /// </param> /// <param name="postalCode"> /// The postal code. /// </param> /// <param name="addressNumber"> /// The address number. /// </param> /// <returns> /// The <see cref="Customer"/>. /// </returns> /// <exception cref="Exception"> /// </exception> public BusinessObjectLayer.Customer Register( string email, string password, string phone, string cellPhone, string firstName, string lastName, string companyName, string postalCode, string addressNumber) { // TODO Input validation. var dalAddress = new DataAccessLayer.Address(); var dalCustomerAddress = new CustomerAddress(); if (this.dalCustomer.GetBy("Email", email) != null) { throw new Exception("Gebruikersnaam is al in gebruik."); } var customer = new BusinessObjectLayer.Customer(); customer.Email = email.Trim(); if (!this.IsValidEmail(customer.Email)) { throw new Exception("Ongeldig e-mailadres."); } customer.Password = password.Trim(); if (string.IsNullOrWhiteSpace(customer.Password)) { throw new Exception("Ongeldig wachtwoord."); } customer.Phone = phone.Trim(); customer.CellPhone = cellPhone.Trim(); customer.Created = DateTime.Now; var address = new Address(); address.AddressNumber = addressNumber.Trim(); address.CompanyName = companyName.Trim(); address.FirstName = firstName.Trim(); if (string.IsNullOrWhiteSpace(address.FirstName)) { throw new Exception("Ongeldige voornaam."); } address.LastName = lastName.Trim(); if (string.IsNullOrWhiteSpace(address.LastName)) { throw new Exception("Ongeldige achternaam."); } address.PostalCode = postalCode.Trim(); address.CountryId = 0; customer = this.dalCustomer.Insert(customer); address = dalAddress.Insert(address); var customerAddress = new BusinessObjectLayer.CustomerAddress(); customerAddress.DefaultInvoice = true; customerAddress.DefaultShipping = true; customerAddress.AddressId = address.Id; customerAddress.CustomerId = customer.Id; dalCustomerAddress.Insert(customerAddress); return customer; }