示例#1
0
        public async Task <IActionResult> Post(UpdateRolePermissionModel model)
        {
            var per = await PerSvc.GetByNameAsync(model.Name);

            if (per != null)
            {
                if (per.Id != model.Id)
                {
                    return(new JsonResult(new APIResult <int> {
                        ErrorMsg = "该权限已存在"
                    })
                    {
                        StatusCode = 400
                    });
                }
            }
            UpdateRolePermissionDTO dto = new UpdateRolePermissionDTO();

            dto.Description = model.Description;
            dto.Id          = model.Id;
            dto.Name        = model.Name;
            await PerSvc.UpdateAsync(dto);

            return(Ok());
        }
示例#2
0
        public async Task <IActionResult> CheckPermission(CheckPermissionModel model)
        {
            var adminUser = await AdminSvc.GetByIdAsync(model.AdminUserId);

            if (adminUser == null)
            {
                return(new JsonResult(new APIResult <long> {
                    ErrorMsg = "管理员不存在"
                })
                {
                    StatusCode = 400
                });
            }
            var permission = await PerSvc.GetByNameAsync(model.PermissionName);

            if (permission == null)
            {
                return(new JsonResult(new APIResult <long> {
                    ErrorMsg = "权限名不存在"
                })
                {
                    StatusCode = 400
                });
            }
            return(new JsonResult(new APIResult <bool> {
                Data = await PerSvc.CheckPermissionAsync(model.AdminUserId, model.PermissionName)
            }));
        }
示例#3
0
        public async Task <IActionResult> Put(AddRolePermissionModel model)
        {
            if (await PerSvc.GetByNameAsync(model.Name) != null)
            {
                return(new JsonResult(new APIResult <int> {
                    ErrorMsg = "该权限已存在"
                })
                {
                    StatusCode = 400
                });
            }
            AddRolePermissionDTO dto = new AddRolePermissionDTO();

            dto.Name        = model.Name;
            dto.Description = model.Description;
            return(new JsonResult(new APIResult <long> {
                Data = await PerSvc.AddNewAsync(dto)
            }));
        }