コード例 #1
0
        public async Task <ActionResult> PutRoles([FromBody] CreateOrUpdateRoleInput input)
        {
            var identityResult = await _roleAppService.EditRoleAsync(input);

            if (identityResult.Succeeded)
            {
                return(Ok());
            }

            return(BadRequest(identityResult.Errors.Select(e => new NameValueDto(e.Code, e.Description))));
        }
コード例 #2
0
        public async Task <ActionResult> CreateOrUpdateRole([FromBody] CreateOrUpdateRoleInput input)
        {
            if (input.Role.Id == Guid.Empty)
            {
                await _roleAppService.AddRoleAsync(input);
            }
            else
            {
                await _roleAppService.EditRoleAsync(input);
            }

            return(Ok(new { success = true }));
        }
コード例 #3
0
        public async Task <ActionResult> CreateOrUpdateRole([FromBody] CreateOrUpdateRoleInput input)
        {
            IdentityResult identityResult;

            if (input.Role.Id == Guid.Empty)
            {
                identityResult = await _roleAppService.AddRoleAsync(input);
            }
            else
            {
                identityResult = await _roleAppService.EditRoleAsync(input);
            }

            if (identityResult.Succeeded)
            {
                return(Ok());
            }

            return(BadRequest(identityResult.Errors.Select(e => new NameValueDto(e.Code, e.Description))));
        }
コード例 #4
0
        public async void Should_Edit_Role()
        {
            var testRole = await CreateAndGetTestRoleAsync();

            var input = new CreateOrUpdateRoleInput
            {
                Role = new RoleDto
                {
                    Id   = testRole.Id,
                    Name = "TestRoleName_Edited_" + Guid.NewGuid()
                },
                GrantedPermissionIds = new List <Guid> {
                    DefaultPermissions.MemberAccess.Id
                }
            };
            await _roleAppService.EditRoleAsync(input);

            var editedTestRole = await _dbContext.Roles.FindAsync(testRole.Id);

            Assert.Contains("TestRoleName_Edited_", editedTestRole.Name);
            Assert.Contains(editedTestRole.RolePermissions, rp => rp.PermissionId == DefaultPermissions.MemberAccess.Id);
        }