/// <summary> /// Saves data for new or edited customer to database. /// </summary> protected void ButtonSave_Click(object sender, EventArgs e) { CustomerController controller = new CustomerController(); ActionServiceReference.Customer customer; if (CustomerId == 0) { customer = new ActionServiceReference.Customer(); } else { customer = controller.GetCustomer(CustomerId); } // Get Company name from page. DetailsViewRow row = DetailsViewCustomer.Rows[1]; TextBox textBox = row.Cells[1].Controls[0] as TextBox; customer.Company = textBox.Text.Trim(); // Get City from page. row = DetailsViewCustomer.Rows[2]; textBox = row.Cells[1].Controls[0] as TextBox; customer.City = textBox.Text.Trim(); // Get Country from page. row = DetailsViewCustomer.Rows[3]; textBox = row.Cells[1].Controls[0] as TextBox; customer.Country = textBox.Text.Trim(); try { if (CustomerId == 0) { controller.AddCustomer(customer); } else { controller.UpdateCustomer(customer); } } catch (ApplicationException ex) { LabelError.Text = ex.Message.Replace(Environment.NewLine, "<br />"); LabelError.Visible = true; return; } // Return to list of customers. Response.Redirect("Customers.aspx"); }
/// <summary> /// Sets datasources and bind data to controls. /// </summary> private void Bind() { // Get customer via Customer Repository. var repository = new CustomerRepository(); ActionServiceReference.Customer customer = repository.GetCustomerWithOrders(CustomerId); // Set company name LabelHeader.Text = "<font color='black'>Orders for:</font> " + customer.Company + " (" + customer.Country + ")"; GridViewOrders.DataSource = customer.Orders; GridViewOrders.DataBind(); }
/// <summary> /// Saves data for new or edited customer to database. /// </summary> protected void ButtonSave_Click(object sender, EventArgs e) { CustomerController controller = new CustomerController(); ActionServiceReference.Customer customer; if (CustomerId == 0) customer = new ActionServiceReference.Customer(); else customer = controller.GetCustomer(CustomerId); // Get Company name from page. DetailsViewRow row = DetailsViewCustomer.Rows[1]; TextBox textBox = row.Cells[1].Controls[0] as TextBox; customer.Company = textBox.Text.Trim(); // Get City from page. row = DetailsViewCustomer.Rows[2]; textBox = row.Cells[1].Controls[0] as TextBox; customer.City = textBox.Text.Trim(); // Get Country from page. row = DetailsViewCustomer.Rows[3]; textBox = row.Cells[1].Controls[0] as TextBox; customer.Country = textBox.Text.Trim(); try { if (CustomerId == 0) controller.AddCustomer(customer); else controller.UpdateCustomer(customer); } catch (ApplicationException ex) { LabelError.Text = ex.Message.Replace(Environment.NewLine, "<br />"); LabelError.Visible = true; return; } // Return to list of customers. Response.Redirect("Customers.aspx"); }