Beispiel #1
0
        private async Task SeedTestUsersAsync()
        {
            if (!await _userService.Users.AnyAsync())
            {
                foreach (var testUser in Users)
                {
                    if (testUser.Id != AppAdministrator.Id)
                    {
                        await _userService.CreateAsync(testUser);

                        foreach (var testUserClaim in UserClaims.Where(userClaim => userClaim.UserId == testUser.Id))
                        {
                            await _userService.AddClaimAsync(testUser, testUserClaim.ToClaim());
                        }

                        foreach (var testUserRole in UserRoles.Where(userRole => userRole.UserId == testUser.Id))
                        {
                            await _userService.AddToRoleAsync(testUser, Roles.Single(role => role.Id == testUserRole.RoleId).Name);
                        }

                        var user = await _userService.FindByIdAsync(testUser.Id.ToString());

                        await _doxatagService.ChangeDoxatagAsync(user, Doxatags.Single(doxatag => doxatag.UserId == user.Id.ConvertTo <UserId>()).Name);
                    }
                }

                Logger.LogInformation("The users being populated...");
            }
            else
            {
                Logger.LogInformation("The users already populated.");
            }
        }
Beispiel #2
0
        public async Task <IActionResult> ChangeDoxatagAsync([FromBody] ChangeDoxatagRequest request)
        {
            var user = await _userService.GetUserAsync(User);

            var result = await _doxatagService.ChangeDoxatagAsync(user, request.Name);

            if (result.IsValid)
            {
                return(this.Ok(_mapper.Map <DoxatagDto>(result.Response)));
            }

            result.AddToModelState(ModelState);

            return(this.BadRequest(new ValidationProblemDetails(ModelState)));
        }