示例#1
0
 public ActionResult Create(PermissionCreateModel model)
 {
     PermService.AddPermission(model.Name, model.Description);
     return(Json(new AjaxResult {
         Status = "ok"
     }));
 }
示例#2
0
        public async Task <IActionResult> CreatePermissionAsync([FromRoute] int groupId, [FromBody] PermissionCreateModel model)
        {
            var currentAccount = await _accountRepository.GetAccountByIdAsync(CurrentAccountId);

            if (currentAccount.GroupId > groupId)
            {
                throw new ForbiddenException(); // the lower the group id, the higher the authority; can only delete the group with authority lower than the current group
            }

            var group = await _groupRepository.GetGroupByIdAsync(groupId);

            var function = await _functionRepository.GetFunctionByIdAsync(model.FunctionId);

            if (group == null)
            {
                throw new NotFound404Exception("group");
            }

            if (function == null)
            {
                throw new NotFound400Exception("function");
            }

            if (await _groupRepository.AnyByPermissionAsync(model.FunctionId, groupId))
            {
                throw new AlreadyExistsException("function");
            }

            var permission = new Permission
            {
                FunctionId = model.FunctionId,
                GroupId    = groupId
            };

            await _groupRepository.CreatePermissionAsync(permission);

            return(Ok(FunctionDTO.GetFrom(function)));
        }
示例#3
0
        public async Task <ActionResult> Create(PermissionCreateModel model)
        {
            long id = await permissionService.AddNew(model.PermissionName, model.Description);

            return(Redirect("Index"));
        }