/// <summary> /// Update form component template data /// </summary> /// <param name="model"></param> /// <returns></returns> public ResponseModel UpdateFormComponentTemplateData(XEditableModel model) { var formComponentTemplate = GetById(model.Pk); if (formComponentTemplate != null) { var property = ReflectionUtilities.GetAllPropertiesOfType(typeof(FormComponentTemplateManageModel)) .FirstOrDefault(p => p.Name.Equals(model.Name, StringComparison.CurrentCultureIgnoreCase)); if (property != null) { object value = model.Value.ToType(property, WorkContext.CurrentTimezone); #region Validate var manageModel = new FormComponentTemplateManageModel(formComponentTemplate); manageModel.SetProperty(model.Name, value); var validationResults = manageModel.ValidateModel(); if (validationResults.Any()) { return(new ResponseModel { Success = false, Message = validationResults.BuildValidationMessages() }); } #endregion formComponentTemplate.SetProperty(model.Name, value); var response = Update(formComponentTemplate); return(response.SetMessage(response.Success ? T("FormComponentTemplate_Message_UpdateFormComponentTemplateInfoSuccessfully") : T("FormComponentTemplate_Message_UpdateFormComponentTemplateInfoFailure"))); } return(new ResponseModel { Success = false, Message = T("FormComponentTemplate_Message_PropertyNotFound") }); } return(new ResponseModel { Success = false, Message = T("FormComponentTemplate_Message_ObjectNotFound") }); }
public ActionResult Edit(FormComponentTemplateManageModel model, SubmitType submit) { if (ModelState.IsValid) { var response = _formComponentTemplateService.SaveFormComponentTemplate(model); SetResponseMessage(response); if (response.Success) { switch (submit) { case SubmitType.Save: return RedirectToAction("Index"); default: return RedirectToAction("Edit", new { id = model.Id }); } } } return View(model); }
/// <summary> /// Save form component template /// </summary> /// <param name="model"></param> /// <returns></returns> public ResponseModel SaveFormComponentTemplate(FormComponentTemplateManageModel model) { ResponseModel response; var formComponentTemplate = GetById(model.Id); if (formComponentTemplate != null) { formComponentTemplate.Name = model.Name; formComponentTemplate.Content = model.Content; response = Update(formComponentTemplate); return(response.SetMessage(response.Success ? T("FormComponentTemplate_Message_UpdateSuccessfully") : T("FormComponentTemplate_Message_UpdateFailure"))); } Mapper.CreateMap <FormComponentTemplateManageModel, FormComponentTemplate>(); formComponentTemplate = Mapper.Map <FormComponentTemplateManageModel, FormComponentTemplate>(model); response = Insert(formComponentTemplate); return(response.SetMessage(response.Success ? T("FormComponentTemplate_Message_CreateSuccessfully") : T("FormComponentTemplate_Message_CreateFailure"))); }