Exemplo n.º 1
0
        public JsonResult Manage(UserModel model, GridManagingModel manageModel)
        {
            if (ModelState.IsValid || manageModel.Operation == GridOperationEnums.Del)
            {
                return Json(_userServices.ManageUser(manageModel.Operation, model));
            }

            return Json(new ResponseModel
                {
                    Success = false,
                    Message = GetFirstValidationResults(ModelState).Message
                });
        }
Exemplo n.º 2
0
        /// <summary>
        /// Manage user
        /// </summary>
        /// <param name="operation">the operation</param>
        /// <param name="model">the user model</param>
        /// <returns></returns>
        public ResponseModel ManageUser(GridOperationEnums operation, UserModel model)
        {
            ResponseModel response;
            Mapper.CreateMap<UserModel, User>();
            User user;
            switch (operation)
            {
                case GridOperationEnums.Edit:
                    user = GetById(model.Id);
                    user.FirstName = model.FirstName;
                    user.LastName = model.LastName;
                    user.Phone = model.Phone;
                    user.Status = model.Status;

                    user.IdentityNumber = model.IdentityNumber;
                    user.RecordActive = model.RecordActive;
                    user.RecordOrder = 0;
                    response = Update(user);
                    return response.SetMessage(response.Success ?
                        _localizedResourceServices.T("AdminModule:::Users:::Messages:::UpdateSuccessfully:::Update user successfully.")
                        : _localizedResourceServices.T("AdminModule:::Users:::Messages:::UpdateFailure:::Update user failed. Please try again later."));

                //case GridOperationEnums.Add:
                //    user = Mapper.Map<UserModel, User>(model);
                //    user.Status = model.Status;

                //    user.RecordOrder = 0;
                //    response = Insert(user);
                //    return response.SetMessage(response.Success ?
                //        _localizedResourceServices.T("AdminModule:::Users:::Messages:::CreateSuccessfully:::Create user successfully.")
                //        : _localizedResourceServices.T("AdminModule:::Users:::Messages:::CreateFailure:::Create user failed. Please try again later."));

                case GridOperationEnums.Del:
                    response = Delete(model.Id);
                    return response.SetMessage(response.Success ?
                        _localizedResourceServices.T("AdminModule:::Users:::Messages:::DeleteSuccessfully:::Delete user successfully.")
                        : _localizedResourceServices.T("AdminModule:::Users:::Messages:::DeleteFailure:::Delete user failed. Please try again later."));
            }
            return new ResponseModel
            {
                Success = false,
                Message = _localizedResourceServices.T("AdminModule:::Users:::Messages:::ObjectNotFounded:::User is not founded.")
            };
        }