/// <summary> /// Update form component data /// </summary> /// <param name="model"></param> /// <returns></returns> public ResponseModel UpdateFormComponentData(XEditableModel model) { var formComponent = GetById(model.Pk); if (formComponent != null) { var property = ReflectionUtilities.GetAllPropertiesOfType(typeof(FormComponentManageModel)) .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 FormComponentManageModel(formComponent); manageModel.SetProperty(model.Name, value); var validationResults = manageModel.ValidateModel(); if (validationResults.Any()) { return(new ResponseModel { Success = false, Message = validationResults.BuildValidationMessages() }); } #endregion formComponent.SetProperty(model.Name, value); var response = Update(formComponent); return(response.SetMessage(response.Success ? T("FormComponent_Message_UpdateFormComponentInfoSuccessfully") : T("FormComponent_Message_UpdateFormComponentInfoFailure"))); } return(new ResponseModel { Success = false, Message = T("FormComponent_Message_PropertyNotFound") }); } return(new ResponseModel { Success = false, Message = T("FormComponent_Message_ObjectNotFound") }); }
public ActionResult Edit(FormComponentManageModel model, SubmitType submit) { if (ModelState.IsValid) { var response = _formComponentService.SaveFormComponent(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 /// </summary> /// <param name="model"></param> /// <returns></returns> public ResponseModel SaveFormComponent(FormComponentManageModel model) { ResponseModel response; var formComponent = GetById(model.Id); if (formComponent != null) { formComponent.Name = model.Name; formComponent.RecordOrder = model.RecordOrder; response = Update(formComponent); return(response.SetMessage(response.Success ? T("FormComponent_Message_UpdateSuccessfully") : T("FormComponent_Message_UpdateFailure"))); } Mapper.CreateMap <FormComponentManageModel, FormComponent>(); formComponent = Mapper.Map <FormComponentManageModel, FormComponent>(model); response = Insert(formComponent); return(response.SetMessage(response.Success ? T("FormComponent_Message_CreateSuccessfully") : T("FormComponent_Message_CreateFailure"))); }