Пример #1
0
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="requestModel"></param>
        /// <returns></returns>
        public BusinessBaseViewModel <string> Update(UpdateSystemRoleRequestModel requestModel)
        {
            var res = new BusinessBaseViewModel <string>()
            {
                Status = ResponseStatus.Fail
            };

            if (requestModel == null)
            {
                res.ErrorMessage = "参数错误";
                return(res);
            }
            if (requestModel.RoleName.IsNullOrWhiteSpace())
            {
                res.ErrorMessage = "角色名称不能为空";
                return(res);
            }
            if (requestModel.Id <= 0)
            {
                res.ErrorMessage = "角色Id不能为空";
                return(res);
            }
            var entity = _systemRoleRepository.FirstOrDefault(x => x.Id != requestModel.Id && x.RoleName == requestModel.RoleName);

            if (entity != null)
            {
                res.ErrorMessage = "角色名称已存在,不能重复添加";
                return(res);
            }

            entity = _systemRoleRepository.FirstOrDefault(x => x.Id == requestModel.Id);

            if (entity == null)
            {
                res.ErrorMessage = "角色不存在或已删除";
                return(res);
            }

            entity.RoleName   = requestModel.RoleName;
            entity.RoleCode   = requestModel.RoleCode;
            entity.Enabled    = requestModel.Enabled;
            entity.RoleDesc   = requestModel.RoleDesc;
            entity.Sort       = requestModel.Sort;
            entity.ModifyTime = DateTime.Now;

            _systemRoleRepository.Update(entity);
            _systemRoleRepository.SaveChanges();

            res.Status = ResponseStatus.Success;
            return(res);
        }
Пример #2
0
        /// <summary>
        /// 更新角色
        /// </summary>
        /// <param name="requestModel"></param>
        /// <returns></returns>
        public ActionResult Update(UpdateSystemRoleRequestModel requestModel)
        {
            var res = _systemRoleService.Update(requestModel);

            return(Content(res.ToJsonString()));
        }