Example #1
0
        /// <summary>
        /// Save form component field
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ResponseModel SaveFormComponentField(FormComponentFieldManageModel model)
        {
            ResponseModel response;
            var           formComponentField = GetById(model.Id);

            if (formComponentField != null)
            {
                formComponentField.FormComponentId = model.FormComponentId;
                formComponentField.Name            = model.Name;
                formComponentField.Attributes      = SerializeUtilities.Serialize(model.Attributes);
                formComponentField.RecordOrder     = model.RecordOrder;
                response = Update(formComponentField);
                return(response.SetMessage(response.Success
                    ? T("FormComponentField_Message_UpdateSuccessfully")
                    : T("FormComponentField_Message_UpdateFailure")));
            }

            formComponentField = new FormComponentField
            {
                FormComponentId = model.FormComponentId,
                Name            = model.Name,
                Attributes      = SerializeUtilities.Serialize(model.Attributes),
                RecordOrder     = model.RecordOrder
            };
            response = Insert(formComponentField);
            return(response.SetMessage(response.Success
                ? T("FormComponentField_Message_CreateSuccessfully")
                : T("FormComponentField_Message_CreateFailure")));
        }
Example #2
0
        /// <summary>
        /// Update form component field data
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ResponseModel UpdateFormComponentFieldData(XEditableModel model)
        {
            var formComponentField = GetById(model.Pk);

            if (formComponentField != null)
            {
                var property =
                    ReflectionUtilities.GetAllPropertiesOfType(typeof(FormComponentFieldManageModel))
                    .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 FormComponentFieldManageModel(formComponentField);
                    manageModel.SetProperty(model.Name, value);

                    var validationResults = manageModel.ValidateModel();

                    if (validationResults.Any())
                    {
                        return(new ResponseModel
                        {
                            Success = false,
                            Message = validationResults.BuildValidationMessages()
                        });
                    }

                    #endregion

                    formComponentField.SetProperty(model.Name, value);

                    var response = Update(formComponentField);
                    return(response.SetMessage(response.Success
                        ? T("FormComponentField_Message_UpdateFormComponentFieldInfoSuccessfully")
                        : T("FormComponentField_Message_UpdateFormComponentFieldInfoFailure")));
                }
                return(new ResponseModel
                {
                    Success = false,
                    Message = T("FormComponentField_Message_PropertyNotFound")
                });
            }
            return(new ResponseModel
            {
                Success = false,
                Message = T("FormComponentField_Message_ObjectNotFound")
            });
        }
        public ActionResult Edit(FormComponentFieldManageModel model, SubmitType submit)
        {
            if (ModelState.IsValid)
            {
                var response = _formComponentFieldService.SaveFormComponentField(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));
        }