// saves data for new or edited member to database. protected void ButtonSave_Click(object sender, EventArgs e) { var service = new Service(); var member = (MemberId == 0) ? new BusinessObjects.Member() : service.GetMember(MemberId); // get email name from page var row = DetailsViewMember.Rows[1]; var textBox = row.Cells[1].Controls[0] as TextBox; member.Email = textBox.Text.Trim(); // get Company name from page. row = DetailsViewMember.Rows[2]; textBox = row.Cells[1].Controls[0] as TextBox; member.CompanyName = textBox.Text.Trim(); // get City from page row = DetailsViewMember.Rows[3]; textBox = row.Cells[1].Controls[0] as TextBox; member.City = textBox.Text.Trim(); // get Country from page row = DetailsViewMember.Rows[4]; textBox = row.Cells[1].Controls[0] as TextBox; member.Country = textBox.Text.Trim(); // validate using business rules engine if (member.IsValid()) { if (MemberId == 0) { service.InsertMember(member); Session["message"] = "New member successfully added"; } else { service.UpdateMember(member); Session["message"] = "Member successfully updated"; } } else { LabelError.Text = member.Errors.Aggregate((current, next) => current + "</br>" + next); PanelError.Visible = true; return; } // return to list of members Response.Redirect(UrlMaker.ToMembers()); }
// establishes the composite menu hierarchy which is present on all pages. protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { // build the composite menu tree // this tree implements the Composite Design Pattern var root = new MenuCompositeItem("root", null); var home = new MenuCompositeItem("home", UrlMaker.ToDefault()); var shop = new MenuCompositeItem("shopping", UrlMaker.ToShopping()); var prod = new MenuCompositeItem("products", UrlMaker.ToProducts()); var srch = new MenuCompositeItem("search", UrlMaker.ToSearch()); var admn = new MenuCompositeItem("administration", UrlMaker.ToAdmin()); var cust = new MenuCompositeItem("members", UrlMaker.ToMembers()); var ordr = new MenuCompositeItem("orders", UrlMaker.ToOrders()); MenuCompositeItem auth; if (Request.IsAuthenticated) { auth = new MenuCompositeItem("logout", UrlMaker.ToLogout()); } else { auth = new MenuCompositeItem("login", UrlMaker.ToLogin()); } shop.Children.Add(prod); shop.Children.Add(srch); admn.Children.Add(cust); admn.Children.Add(ordr); root.Children.Add(home); root.Children.Add(shop); root.Children.Add(admn); root.Children.Add(auth); TheMenuComposite.MenuItems = root; } }
// cancel the page and redirect user to page with list of members protected void ButtonCancel_Click(object sender, EventArgs e) { Response.Redirect(UrlMaker.ToMembers()); }