/// <summary> /// Populates defaults and opens edit form to add new record /// GET: /Admin/ContactUs/Create /// </summary> public ActionResult Create() { Breadcrumbs.Current.AddBreadcrumb(3, "Add Contact Us"); var record = new Models.ContactUs(); // any default values can be set here or in partial class ContactUs.InitDefaults() return(View("ContactUsEdit", record)); }
protected ActionResult ProcessForm(Models.ContactUs record) { try { record.UpdateFromRequest(); // read subform or related checkboxes here eg record.Lines.UpdateFromRequest(); Validate(record); if (BewebModelState.IsValid()) { Save(record, record.IsNewRecord); Web.InfoMessage = "Contact Us " + record.GetName() + " saved."; } } catch (UserErrorException e) { BewebModelState.AddModelError("Record", e.Message); } if (!BewebModelState.IsValid()) { // invalid so redisplay form with validation message(s) return(View("ContactUsEdit", record)); } else if (Web.Request["SaveAndRefreshButton"] != null) { return(RedirectToEdit(record.ID)); } else if (Web.Request["DuplicateButton"] != null) { var newRecord = new Models.ContactUs(); newRecord.UpdateFrom(record); newRecord.Save(); Web.InfoMessage = "Copy of Contact Us " + record.GetName() + " created. You are now editing the new copy."; return(RedirectToEdit(newRecord.ID)); } else { return(RedirectToReturnPage()); } }
private void Save(Models.ContactUs record, bool isNew) { // add any code to update other fields/tables here record.Save(); // save subform or related checkboxes here eg record.Lines.Save(); }
private void Validate(Models.ContactUs record) { // add any code to check for validity //BewebModelState.AddModelError("Record", "Suchandsuch cannot be whatever."); }