Exemplo n.º 1
0
        private async Task SeedUsers()
        {
            var users = await _userService.BrowswseDTOAsync();

            if (users.Any())
            {
                return;
            }
            {
                Random random = new Random();
                for (int i = 0; i < 5; i++)
                {
                    await _userService.RegisterAsync($"user{i}", $"user{i}@email.com", "secret", Role.User);

                    _logger.LogTrace($"Created user{i}");
                    for (int j = 0; j < 5; j++)
                    {
                        var categories = (await _categoryService.BrowseDTOAsync()).ToList();
                        var count      = categories.Count - 1;
                        var category   = categories[random.Next(0, count)];
                        var user       = await _userService.GetUserDTO($"user{i}@email.com");

                        await _userAdService.AddAsync(user.Id, category.Id
                                                      , $"ad by user{i}", Guid.NewGuid().ToString(), DateTime.UtcNow.AddYears(3));

                        _logger.LogTrace($"Created {j}th ad for user{i}");
                    }
                }
                await _userService.RegisterAsync($"admin", $"*****@*****.**", "secret", Role.Admin);

                _logger.LogTrace($"Created admin");
                for (int j = 0; j < 5; j++)
                {
                    var categories = (await _categoryService.BrowseDTOAsync()).ToList();
                    var count      = categories.Count - 1;
                    var category   = categories[random.Next(0, count)];
                    var user       = await _userService.GetUserDTO($"*****@*****.**");

                    await _userAdService.AddAsync(user.Id, category.Id
                                                  , $"ad by admin", Guid.NewGuid().ToString(), DateTime.UtcNow.AddYears(3));

                    _logger.LogTrace($"Created ad for admin");
                }
            }
        }
Exemplo n.º 2
0
 public async Task HandleAsync(CreateUserAd command)
 {
     await _useradService.AddAsync(command.UserId, command.CategoryID, command.Name,
                                   command.Content, command.ExpiryDate);
 }