public virtual ActionResult SaveElement(long formId, FormElementViewModel model) { FormsHelper.ValidateFormElement(model, ModelState); if (ModelState.IsValid) { FormsHelper.UpdateFormElement(model); var form = formsService.Find(formId); if (form == null || !permissionService.IsAllowed((Int32)FormOperations.Manage, this.CorePrincipal(), typeof(Form), form.Id, IsFormOwner(form), PermissionOperationLevel.Object)) { throw new HttpException((int)HttpStatusCode.NotFound, HttpContext.Translate("Messages.NotFound", ResourceHelper.GetControllerScope(this))); } var formElement = new FormElement(); bool isEdited = model.Id > 0; if (isEdited) { formElement = formsElementService.Find(model.Id); } else { formElement.Form = form; formElement.OrderNumber = formsElementService.GetLastOrderNumber(formElement.Form.Id); } if (formsElementService.Save(model.MapTo(formElement))) { if (isEdited) { //save locale var localeService = ServiceLocator.Current.GetInstance <IFormElementLocaleService>(); FormElementLocale locale = localeService.GetLocale(formElement.Id, model.SelectedCulture); locale = model.MapLocaleTo(locale ?? new FormElementLocale { FormElement = formElement }); localeService.Save(locale); } Success(HttpContext.Translate("Messages.FormElementSaveSuccess", ResourceHelper.GetControllerScope(this)) /*"Sucessfully save form element."*/); return(RedirectToAction(FormsMVC.Forms.ShowFormElements(formId))); } } Error(HttpContext.Translate("Messages.ElementValidationError", ResourceHelper.GetControllerScope(this)) /*"Validation errors occurred while processing this form. Please take a moment to review the form and correct any input errors before continuing."*/); return(View("EditFormElement", model)); }
public virtual ActionResult SaveElement(long formId, FormElementViewModel model) { FormsHelper.ValidateFormElement(model, ModelState); if (ModelState.IsValid) { FormsHelper.UpdateFormElement(model); var form = formsService.Find(formId); if (form == null || !permissionService.IsAllowed((Int32)FormOperations.Manage, this.CorePrincipal(), typeof(Form), form.Id, IsFormOwner(form), PermissionOperationLevel.Object)) { throw new HttpException((int)HttpStatusCode.NotFound, HttpContext.Translate("Messages.NotFound", ResourceHelper.GetControllerScope(this))); } var formElement = new FormElement(); bool isEdited = model.Id > 0; if (isEdited) { formElement = formsElementService.Find(model.Id); } else { formElement.Form = form; formElement.OrderNumber = formsElementService.GetLastOrderNumber(formElement.Form.Id); } if (formsElementService.Save(model.MapTo(formElement))) { if (isEdited) { //save locale var localeService = ServiceLocator.Current.GetInstance<IFormElementLocaleService>(); FormElementLocale locale = localeService.GetLocale(formElement.Id, model.SelectedCulture); locale = model.MapLocaleTo(locale ?? new FormElementLocale { FormElement = formElement }); localeService.Save(locale); } Success(HttpContext.Translate("Messages.FormElementSaveSuccess", ResourceHelper.GetControllerScope(this))/*"Sucessfully save form element."*/); return RedirectToAction(FormsMVC.Forms.ShowFormElements(formId)); } } Error(HttpContext.Translate("Messages.ElementValidationError", ResourceHelper.GetControllerScope(this))/*"Validation errors occurred while processing this form. Please take a moment to review the form and correct any input errors before continuing."*/); return View("EditFormElement", model); }