/// <summary> /// Saves data for new or edited customer to database. /// </summary> protected void ButtonSave_Click(object sender, EventArgs e) { var repository = new CustomerRepository(); ActionServiceReference.Customer customer; if (CustomerId == 0) { customer = new ActionServiceReference.Customer(); } else { customer = repository.GetCustomer(CustomerId); } // Get Company name from page. var row = DetailsViewCustomer.Rows[1]; var 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) { repository.AddCustomer(customer); } else { repository.UpdateCustomer(customer); } } catch (ApplicationException ex) { LabelError.Text = ex.Message.Replace(Environment.NewLine, "<br />"); PanelError.Visible = true; return; } // Return to list of customers. Response.Redirect(UrlMaker.ToCustomers()); }
// private Helper private void SetCustomerViewData(int?customerId = 0) { ViewData["BreadCrumbs"] = new List <BreadCrumb> { new BreadCrumb { Url = UrlMaker.ToDefault(), Title = "home" }, new BreadCrumb { Url = UrlMaker.ToAdmin(), Title = "administration" }, new BreadCrumb { Url = UrlMaker.ToCustomers(), Title = "customers" }, new BreadCrumb { Title = "customer details" } }; ViewData["CustomerImage"] = imageService + "GetCustomerImageLarge/" + customerId; }
/// <summary> /// Cancel the page and redirect user to page with list of customers. /// </summary> protected void ButtonCancel_Click(object sender, EventArgs e) { Response.Redirect(UrlMaker.ToCustomers()); }