private async Task SeedData(ApplicationDbContext context) { var user = new ApplicationUser() { FirstName = "Kaplata", LastName = "Jormanov", UserName = "******", Email = "*****@*****.**", EmailConfirmed = true, PasswordHash = "someRandomHash", }; context.Users.Add(user); var location = new Location() { Name = "Perushtica", Lat = "53.555", Lng = "23.456", Type = WilderExperience.Data.Models.Enums.Type.City, }; context.Locations.Add(location); await context.SaveChangesAsync(); var experience = new Experience() { Title = "Test", Description = "Description of test", AuthorId = context.Users.First().Id, LocationId = context.Locations.First().Id, }; context.Experiences.Add(experience); await context.SaveChangesAsync(); var image = new ExperienceImage() { Name = "Test", ExperienceId = context.Experiences.First().Id, UserId = context.Users.First().Id, }; context.ExperienceImages.Add(image); await context.SaveChangesAsync(); }
public async Task SeedAsync(ApplicationDbContext dbContext, IServiceProvider serviceProvider) { if (dbContext.Experiences.Any() == true) { return; } var desc = ""; var file = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "data", "SampleDescription.txt"); using (FileStream fs = File.OpenRead(file)) { using (StreamReader reader = new StreamReader(fs)) { desc = reader.ReadToEnd(); } } var locationId = dbContext.Locations.Where(x => x.Name == "Plovdiv").First().Id; var userId = dbContext.Users.First().Id; for (int i = 1; i <= 10; i++) { var experience = new Experience() { LocationId = locationId, Title = "Lorem Ipsum Dolar", Description = desc, AuthorId = userId, DateOfVisit = DateTime.UtcNow, Intensity = WilderExperience.Data.Models.Enums.Intensity.High, Guide = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor.", }; await dbContext.Experiences.AddAsync(experience); await dbContext.SaveChangesAsync(); var experienceImage = new ExperienceImage() { ExperienceId = experience.Id, Name = i + ".jpg", UserId = userId, }; await dbContext.ExperienceImages.AddAsync(experienceImage); await dbContext.SaveChangesAsync(); var experienceRating = new Rating() { ExperienceId = experience.Id, UserId = userId, RatingNumber = new Random().Next(1, 6), }; await dbContext.Ratings.AddAsync(experienceRating); await dbContext.SaveChangesAsync(); } }