private static async Task<int> CreateAreaAsync(List<User> users, int usersIndex, CreateAreaCommandHandler commandHandler, string title) { var author = users[usersIndex++ % users.Count()]; var command = new CreateArea(Guid.NewGuid(), author.Id, title, RandomTextGenerator.GetRandomParagraph(3)); await commandHandler.Handle(command); return usersIndex; }
private static async Task CreateAreasAsync(ICommandsDbContext commandsDbContext, IMediator bus) { var areasCount = await commandsDbContext.Ideas.CountAsync("{}"); if (areasCount > 0) return; var users = await commandsDbContext.Users.Find("{}").Limit(100).ToListAsync(); var usersIndex = 0; areasCount = 50; var commandHandler = new CreateAreaCommandHandler(commandsDbContext, bus); usersIndex = await CreateAreaAsync(users, usersIndex, commandHandler, "Canteen"); usersIndex = await CreateAreaAsync(users, usersIndex, commandHandler, "Dell @ Limerick"); usersIndex = await CreateAreaAsync(users, usersIndex, commandHandler, "Dell Sales Application"); usersIndex = await CreateAreaAsync(users, usersIndex, commandHandler, "Employee Resource Group"); usersIndex = await CreateAreaAsync(users, usersIndex, commandHandler, "Global Operations"); usersIndex = await CreateAreaAsync(users, usersIndex, commandHandler, "IT"); usersIndex = await CreateAreaAsync(users, usersIndex, commandHandler, "Sports & Social"); usersIndex = await CreateAreaAsync(users, usersIndex, commandHandler, "Tech Central"); //for (int i = 0; i != areasCount; ++i) //{ // var title = RandomTextGenerator.GetRandomSentence(5); // usersIndex = await CreateAreaAsync(users, usersIndex, commandHandler, title); //} }