Created
April 12, 2019 21:53
-
-
Save Rudyzio/bcac3925b580387265e693a23131f643 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DataSeeder | |
{ | |
public static void Initialize(ApplicationDbContext context) | |
{ | |
if (!context.Users.Any()) | |
{ | |
var users = new List<User>() | |
{ | |
new User { /*Id = 1,*/ Name = "John", Email = "john@john.com" }, | |
new User { /*Id = 2,*/ Name = "Michael", Email = "michael@michael.com" } | |
}; | |
context.Users.AddRange(users); | |
context.SaveChanges(); | |
} | |
if (!context.Recipes.Any()) | |
{ | |
var recipes = new List<Recipe>() | |
{ | |
new Recipe { /* Id = 1 */ Name = "Pizza", Description = "A random description from a pizza", Difficulty = RecipeDifficulty.MEDIUM, ImagePath = "https://upload.wikimedia.org/wikipedia/commons/a/a4/Pizza.jpg", Time = 30, UserId = 1 } | |
}; | |
context.Recipes.AddRange(recipes); | |
context.SaveChanges(); | |
} | |
if (!context.Ingredients.Any()) | |
{ | |
var ingredients = new List<Ingredient>() | |
{ | |
new Ingredient { /* Id = 1 */ Name = "Cheese", Amount = 1, RecipeId = 1 }, | |
new Ingredient { /* Id = 2 */ Name = "Tomato", Amount = 2, RecipeId = 1 } | |
}; | |
context.Ingredients.AddRange(ingredients); | |
context.SaveChanges(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment