Beispiel #1
0
        public async Task <ApiResult> Update(RoleReq req)
        {
            if (req == null)
            {
                return(Error("请求参数不能为空"));
            }
            if (req.Id == 0)
            {
                return(await Insert(req));
            }

            var model = await _sysRoleService.GetByIdAsync(req.Id);

            model.Name       = req.Name;
            model.Remark     = req.Remark;
            model.UpdateBy   = CurrentUser.UserId;
            model.UpdateTime = DateTime.Now;
            var res = await _sysRoleService.UpdateAsync(model);

            if (res > 0)
            {
                return(Success("更新成功"));
            }
            return(Success("更新失败"));
        }
Beispiel #2
0
        public async Task <ApiResult> Insert(RoleReq req)
        {
            if (req == null)
            {
                return(Error("请求参数不能为空"));
            }
            if (string.IsNullOrEmpty(req.Name))
            {
                return(Error("名字不能为空"));
            }

            SysRole role = new SysRole
            {
                Name     = req.Name,
                Remark   = req.Remark,
                CreateBy = CurrentUser.UserId
            };
            var res = await _sysRoleService.InsertAsync(role);

            if (res > 0)
            {
                return(Success("添加成功"));
            }
            return(Success("添加失败"));
        }