Beispiel #1
0
        /// <summary>
        /// Update user data
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ResponseModel UpdateUserData(XEditableModel model)
        {
            var user = GetById(model.Pk);

            if (user != null)
            {
                object value = model.Value;
                if (model.Name.Equals("BirthDay"))
                {
                    value = model.Value.ToDate();
                }
                user.SetProperty(model.Name, value);
                var response = Update(user);
                if (user.Id == WorkContext.CurrentUser.Id && response.Success)
                {
                    WorkContext.CurrentUser = user;
                }
                return(response.SetMessage(response.Success ?
                                           _localizedResourceServices.T("AdminModule:::Users:::Messages:::UpdateUserInfoSuccessfully:::Update user info successfully.")
                    : _localizedResourceServices.T("AdminModule:::Users:::Messages:::UpdateUserInfoFailure:::Update user info failed. Please try again later.")));
            }
            return(new ResponseModel
            {
                Success = false,
                Message = _localizedResourceServices.T("AdminModule:::Users:::Messages:::ObjectNotFounded:::User is not founded.")
            });
        }
        /// <summary>
        /// Update value for property of model
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ResponseModel UpdateAssociateTypeData(XEditableModel model)
        {
            var associateType = GetById(model.Pk);

            if (associateType != null)
            {
                var property =
                    ReflectionUtilities.GetAllPropertiesOfType(typeof(AssociateTypeManageModel))
                    .FirstOrDefault(p => p.Name.Equals(model.Name, StringComparison.CurrentCultureIgnoreCase));
                if (property != null)
                {
                    //Generate property value
                    object value = model.Value.ToType(property, WorkContext.CurrentTimezone);

                    #region Validate

                    var manageModel = new AssociateTypeManageModel(associateType);
                    manageModel.SetProperty(model.Name, value);

                    var validationResults = manageModel.ValidateModel();

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

                    #endregion

                    associateType.SetProperty(model.Name, value);
                    var response = Update(associateType);

                    return(response.SetMessage(response.Success
                        ? T("AssociateType_Message_UpdateAssociateTypeInfoSuccessfully")
                        : T("AssociateType_Message_UpdateAssociateTypeInfoFailure")));
                }

                return(new ResponseModel
                {
                    Success = false,
                    Message = T("AssociateType_Message_PropertyNotFound")
                });
            }

            return(new ResponseModel
            {
                Success = false,
                Message = T("AssociateType_Message_ObjectNotFound")
            });
        }
        public JsonResult UpdateLocationData(XEditableModel model)
        {
            if (ModelState.IsValid)
            {
                return(Json(_locationService.UpdateLocationData(model)));
            }

            return(Json(new ResponseModel
            {
                Success = false,
                Message = ModelState.BuildValidationMessages()
            }));
        }
Beispiel #4
0
        public JsonResult UpdateUserData(XEditableModel model)
        {
            if (ModelState.IsValid)
            {
                return(Json(_userServices.UpdateUserData(model)));
            }

            return(Json(new ResponseModel
            {
                Success = false,
                Message = GetFirstValidationResults(ModelState).Message
            }));
        }
        public JsonResult UpdateFormComponentFieldData(XEditableModel model)
        {
            if (ModelState.IsValid)
            {
                return(Json(_formComponentFieldService.UpdateFormComponentFieldData(model)));
            }

            return(Json(new ResponseModel
            {
                Success = false,
                Message = ModelState.BuildValidationMessages()
            }));
        }
        /// <summary>
        /// Update localize resource
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ResponseModel UpdateLocalizedResource(XEditableModel model)
        {
            var currentCuture    = WorkContext.CurrentCulture;
            var localizeResource = FetchFirst(l => l.Language.Key.Equals(currentCuture) && l.TextKey.Equals(model.Name));

            if (localizeResource != null)
            {
                localizeResource.TranslatedValue = model.Value;
                var response = Update(localizeResource);
                if (response.Success)
                {
                    RefreshDictionary();
                }
                return(response.SetMessage(response.Success
                    ? T("LocalizedResource_Message_UpdateSuccessfully")
                    : T("LocalizedResource_Message_UpdateFailure")));
            }

            return(new ResponseModel
            {
                Success = false,
                Message = T("LocalizedResource_Message_ObjectNotFound")
            });
        }