protected override void Seed(Model.ServiceDbContext context) { // This method will be called after migrating to the latest version. // You can use the DbSet<T>.AddOrUpdate() helper extension method // to avoid creating duplicate seed data. MigrationSeed.SeedAll(); }
/// <summary> /// Makes sure we have placeholder locations in the database, if we find out that it's empty. /// </summary> private void SeedLocations() { Model.ServiceDbContext db = new Model.ServiceDbContext(); int count = db.Locations.Count <Location>(); if (count == 0) { MigrationSeed.SeedLocations(); foreach (var location in MigrationSeed.Locations) { RegisterLocation(location.Name, location.Type, location.Parent?.Name); } } }
/// <summary> /// Makes sure we have placeholder users in the database, if we find out that it's empty. /// </summary> private void SeedUsers() { Model.ServiceDbContext db = new Model.ServiceDbContext(); int count = db.Users.Count(); if (count == 0) { MigrationSeed.SeedUsers(); foreach (var user in MigrationSeed.Users) { RegisterUser(user.Name, user.Email, "http://test.com/image.png", "password"); } } }
private void SeedAds() { //TODO: Refactor var db = DbContextControl.GetNew(); if (db.Ads.Count() == 0) { if (db.Users.Count() == 0) { MigrationSeed.SeedUsers(); } MigrationSeed.SeedAds(); foreach (var ad in MigrationSeed.Ads) { PostAd(ad.Author.Email, ad.Title, ad.Content, ad.Location.Name, ad.Type); } var blueCar = MigrationSeed.Ads.FirstOrDefault(a => a.Title == "Selling blue sports car"); ReserveAd(blueCar?.Id, "*****@*****.**"); CommentControl.GetInstance().PostComment(blueCar.Id, "Interested!", "*****@*****.**"); } }