Exemplo n.º 1
0
        public async Task <ActionResult> PostRoles([FromBody] CreateOrUpdateRoleInput input)
        {
            var identityResult = await _roleAppService.AddRoleAsync(input);

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

            return(BadRequest(identityResult.Errors.Select(e => new NameValueDto(e.Code, e.Description))));
        }
Exemplo n.º 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 }));
        }
Exemplo n.º 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))));
        }
        public async void Should_Add_Role()
        {
            var input = new CreateOrUpdateRoleInput
            {
                Role = new RoleDto
                {
                    Id   = Guid.NewGuid(),
                    Name = "TestRoleName_" + Guid.NewGuid()
                },
                GrantedPermissionIds = new List <Guid> {
                    DefaultPermissions.MemberAccess.Id
                }
            };

            await _roleAppService.AddRoleAsync(input);

            await _dbContext.SaveChangesAsync();

            var dbContextFromAnotherScope = TestServer.Host.Services.GetRequiredService <NucleusDbContext>();
            var insertedTestRole          = await dbContextFromAnotherScope.Roles.FindAsync(input.Role.Id);

            Assert.NotNull(insertedTestRole);
            Assert.Equal(1, insertedTestRole.RolePermissions.Count);
        }