// constructor for loading an EXISTING Customer - This constructor DOES NOT create a new GUID public Customer(Guid personId, string firstName, string lastName, string phoneNumber, string emailAddress, Guid customerId, Address mailingAddress, Address billingAddress) : base(personId, firstName, lastName, phoneNumber, emailAddress) { _customerId = customerId; _mailingAddress = mailingAddress; _billingAddress = billingAddress; base.PersonType = Enumerations.PersonType.Customer; }
// constructor for NEW Customer - This constructor creates a GUID for the new Customer public Customer(string firstName, string lastName, string phoneNumber, string emailAddress, Address mailingAddress, Address billingAddress) : base(firstName, lastName, phoneNumber, emailAddress) { _customerId = Guid.NewGuid(); _mailingAddress = mailingAddress; _billingAddress = billingAddress; base.PersonType = Enumerations.PersonType.Customer; }
public static BusinessObject.Address ToBusinessObject(Entities.Address entity) { if (entity == null) return null; BusinessObject.Address businessObject = new BusinessObject.Address { AddressId = entity.AddressId, PersonId = entity.PersonId, StreetNumber = entity.StreetNumber, StreetName = entity.StreetName, AddressCity = entity.AddressCity, AddressState = entity.AddressState, AddressZip = entity.AddressZip, AddressType = (Enumeration.AddressType)entity.AddressTypeId }; return businessObject; }
public static Entities.Address ToEntity(BusinessObject.Address businessObject) { if (businessObject == null) { return(null); } Entities.Address entity = new Entities.Address { AddressId = businessObject.AddressId, PersonId = businessObject.PersonId, StreetNumber = businessObject.StreetNumber, StreetName = businessObject.StreetName, AddressCity = businessObject.AddressCity, AddressState = businessObject.AddressState, AddressZip = businessObject.AddressZip, AddressTypeId = (int)businessObject.AddressType }; return(entity); }
public static BusinessObject.Address ToBusinessObject(Entities.Address entity) { if (entity == null) { return(null); } BusinessObject.Address businessObject = new BusinessObject.Address { AddressId = entity.AddressId, PersonId = entity.PersonId, StreetNumber = entity.StreetNumber, StreetName = entity.StreetName, AddressCity = entity.AddressCity, AddressState = entity.AddressState, AddressZip = entity.AddressZip, AddressType = (Enumeration.AddressType)entity.AddressTypeId }; return(businessObject); }
// Begin CREATE CUSTOMER button click event private void btnCreateCustomer_Click(object sender, EventArgs e) { // BEGIN USER INPUT DATA VALIDATION..... // Verify that PERSONAL information was not left blank if ((tbx_FirstName.Text == "") || (tbx_LastName.Text == "") || (tbx_PhoneNumber.Text == "") || (tbx_EMail.Text == "")) { // If any personal information was blank, display error and break code ApplicationObjects.DisplayInvalidInput("Please make sure that you have filled out all of the personal fields and try again."); return; } // Verify that MAILING address information was not left blank if ((tbx_MailingStreetNumber.Text == "") || (tbx_MailingStreetName.Text == "") || (tbx_MailingCity.Text == "") || (tbx_MailingState.Text == "") || (tbx_MailingZipCode.Text == "")) { // If any mailing address information was blank, display error and break code ApplicationObjects.DisplayInvalidInput("Please make sure that you have filled out all of the mailing address fields and try again."); return; } // Verify that BILLING address information was not left blank if ((tbx_BillingStreetNumber.Text == "") || (tbx_BillingStreetName.Text == "") || (tbx_BillingCity.Text == "") || (tbx_BillingState.Text == "") || (tbx_BillingZipCode.Text == "")) { // If any billing address information was blank, display error and break code ApplicationObjects.DisplayInvalidInput("Please make sure that you have filled out all of the billing address fields and try again."); return; } // Variable used in TryParse functions long number; // Validate numeric input for phone number if ((!long.TryParse((tbx_PhoneNumber.Text), out number)) || (tbx_PhoneNumber.Text.Length != 10)) { // If phone number input was not numeric, display error and break code ApplicationObjects.DisplayInvalidInput("Invalid phone number entered. Please enter 10 digits (no dashes) & try again."); return; } // validate email address format if (!ApplicationObjects.EmailIsValid(tbx_EMail.Text)) { // If email address was not in specified format, display error and break code ApplicationObjects.DisplayInvalidInput("Invalid e-mail address entered. Please try again."); return; } // Validate numeric input for street numbers if ((!long.TryParse((tbx_MailingStreetNumber.Text), out number)) || (!long.TryParse((tbx_BillingStreetNumber.Text), out number))) { // If street number input was not numeric, display error and break code ApplicationObjects.DisplayInvalidInput("Invalid street number entered. Please enter only numeric values & try again."); return; } // Verify that the state is only 2 characters if ((tbx_MailingState.Text.Length != 2) || (tbx_BillingState.Text.Length != 2)) { // If state input does not have only 2 characters, display error and break code ApplicationObjects.DisplayInvalidInput("Invalid state entered. Please enter a 2-letter state abbreviation & try again."); return; } // Validate numeric input for zip codes if ((!long.TryParse((tbx_MailingZipCode.Text), out number)) || (!long.TryParse((tbx_BillingZipCode.Text), out number))) { // If zip code input was not numeric, display error and break code ApplicationObjects.DisplayInvalidInput("Invalid zip code entered. Please enter only numeric values & try again."); return; } // If zip is numeric, validate only 5 digits else if ((tbx_MailingZipCode.Text.Length != 5) || (tbx_BillingZipCode.Text.Length != 5)) { // If zip code does not have only 5 characters, display error and break code ApplicationObjects.DisplayInvalidInput("Invalid zip code entered. Please enter only 5 digits & try again."); return; } // .....END USER INPUT DATA VALIDATION // Populate customer object with user input Customer customer = new Customer(); customer.FirstName = tbx_FirstName.Text; customer.LastName = tbx_LastName.Text; customer.PhoneNumber = tbx_PhoneNumber.Text; customer.EmailAddress = tbx_EMail.Text; // Populate mailing address object with user input Address mailingAddress = new Address(); mailingAddress.PersonId = customer.PersonId; mailingAddress.StreetNumber = int.Parse(tbx_MailingStreetNumber.Text); mailingAddress.StreetName = tbx_MailingStreetName.Text; mailingAddress.AddressCity = tbx_MailingCity.Text; mailingAddress.AddressState = tbx_MailingState.Text; mailingAddress.AddressZip = tbx_MailingZipCode.Text; mailingAddress.AddressType = AddressType.Mailing; // Populate billing address object with user input Address billingAddress = new Address(); billingAddress.PersonId = customer.PersonId; billingAddress.StreetNumber = int.Parse(tbx_BillingStreetNumber.Text); billingAddress.StreetName = tbx_BillingStreetName.Text; billingAddress.AddressCity = tbx_BillingCity.Text; billingAddress.AddressState = tbx_BillingState.Text; billingAddress.AddressZip = tbx_BillingZipCode.Text; billingAddress.AddressType = AddressType.Billing; // Transaction to perform 4 inter-related data inserts on multiple database tables using (TransactionScope scope = new TransactionScope()) { int returnValue = 1; // Write PERSON record to database BusinessObjects _personBusinessObject = new BusinessObjects(); returnValue = _personBusinessObject.InsertPersonFromCustomer(customer); if (returnValue == 1) { // If insert fails, rollback transaction & display error message scope.Dispose(); ApplicationObjects.DisplayDataStatus(returnValue); return; } // Write CUSTOMER record to database BusinessObjects _customerBusinessObject = new BusinessObjects(); returnValue = _customerBusinessObject.InsertCustomer(customer); if (returnValue == 1) { // If insert fails, rollback transaction & display error message scope.Dispose(); ApplicationObjects.DisplayDataStatus(returnValue); return; } // Write MAILING ADDRESS record to database BusinessObjects _mailingAddressBusinessObject = new BusinessObjects(); returnValue = _mailingAddressBusinessObject.InsertAddress(mailingAddress); if (returnValue == 1) { // If insert fails, rollback transaction & display error message scope.Dispose(); ApplicationObjects.DisplayDataStatus(returnValue); return; } // Write BILLING ADDRESS record to database BusinessObjects _billingAddressBusinessObject = new BusinessObjects(); returnValue = _billingAddressBusinessObject.InsertAddress(billingAddress); if (returnValue == 1) { // If insert fails, rollback transaction & display error message scope.Dispose(); ApplicationObjects.DisplayDataStatus(returnValue); return; } // Committ data transaction & display success message scope.Complete(); ApplicationObjects.DisplayDataStatus(returnValue); }// End transaction _loginForm.ShowCustomerInfoForm(userAccount, _loginForm); this.Close(); }
public string DeleteAddress(Address address) { //Add code here to delete address return "Address has been deleted"; }
private void btnSave_Click(object sender, EventArgs e) { //populate objects with UI data //ORDER OrderStatus orderStatus = (OrderStatus)Enum.Parse(typeof(OrderStatus), this.cboxOrderStatus.Text); order.OrderStatus = orderStatus; //CUSTOMER char[] delimiterChars = { ' ' }; string[] names = this.txtCustomer.Text.Split(delimiterChars); Address mailingAddress = new Address { StreetNumber = Convert.ToInt32(this.txtStreetNumber.Text), StreetName = this.txtStreetName.Text, AddressCity = this.txtCity.Text, AddressState = this.txtState.Text, AddressZip = this.txtZipcode.Text }; Address billingAddress = new Address { StreetNumber = Convert.ToInt32(this.txtBillingStreetNumber.Text), StreetName = this.txtBillingStreetName.Text, AddressCity = this.txtBillingCity.Text, AddressState = this.txtBillingState.Text, AddressZip = this.txtBillingZipcode.Text }; Customer customer = new Customer { CustomerId = Guid.NewGuid(), FirstName = names[0], LastName = names[1], PhoneNumber = this.txtPhoneNumber.Text, EmailAddress = this.txtEmail.Text, MailingAddress = mailingAddress, BillingAddress = billingAddress }; order.Person = (Person)customer; if (order != null && customer != null) { int returnValue = ApplicationObjects.CreateCustomer(customer); if (returnValue == 0) returnValue = ApplicationObjects.CreateOrder(order); ApplicationObjects.DisplayDataStatus(returnValue); if (returnValue == 0) { //Return to order list _loginForm.ShowOrdersForm(userAccount, _loginForm); this.Close(); } } }