private async Task SeedGeneratedPostsModels() { if (!_context.BlogPosts.Any()) { if (_context.Users.Any()) { var users = _context.Users.ToList(); for (int i = 0; i < NumberGenerator.RandomNumber(20, 40); i++) { var newPostItem = new BlogPost { AuthorId = users[NumberGenerator.RandomNumber(0, users.Count - 1)].Id, CreatedOn = DateTime.Now.AddDays(NumberGenerator.RandomNumber(1, 10)), Summary = StringGenerator.RandomStringWithSpaces(40, 200), Title = StringGenerator.RandomStringWithSpaces(10, 60), Description = StringGenerator.RandomStringWithSpaces(200, 2000), }; _context.BlogPosts.Add(newPostItem); } await _context.SaveChangesAsync(); } } }
private async Task SeedGeneratedBlogItemsModels() { if (!_context.BlogItems.Any()) { if (_context.Users.Any()) { var user = _context.Users.FirstOrDefault(); for (int i = 0; i < NumberGenerator.RandomNumber(6, 12); i++) { var newBlogItem = new BlogItem { AuthorId = user.Id, CreatedOn = DateTime.Now.AddDays(NumberGenerator.RandomNumber(1, 10)), Summary = StringGenerator.RandomStringWithSpaces(40, 200), Title = StringGenerator.RandomStringWithSpaces(10, 60), Description = StringGenerator.RandomStringWithSpaces(200, 2000), }; _context.BlogItems.Add(newBlogItem); } await _context.SaveChangesAsync(); } } }