public static void Seed(FeedTheCrowdContext _context) { string line; int count = 1; if (!_context.Recipe.Any() || !_context.Product.Any()) { using (StreamReader reader = new StreamReader(new FileStream(fileName, FileMode.Open))) { while ((line = reader.ReadLine()) != null) { SeedTheDatabase(line, _context, count); count++; } } } }
public static void SeedTheDatabase(string line, FeedTheCrowdContext _context, int count) { string[] mas = line.Split(';'); string ing = mas[5]; string qua = mas[6]; string[] ings = ing.Split(':').Where(x => !string.IsNullOrEmpty(x)).ToArray(); string[] quas = qua.Split(':').Where(x => !string.IsNullOrEmpty(x)).ToArray(); var recipe = new Recipe { Title = mas[1], Time = mas[0], Image = mas[2], Description = mas[4], Servings = Int32.Parse(mas[3]), }; _context.Add(recipe); _context.SaveChanges(); for (int i = 0; i < ings.Length; i++) { var product = new Product { Name = ings[i], Quantity = Double.Parse(quas[i]), FkRecipe = count }; _context.Add(product); } _context.SaveChanges(); }
public AuthRepository(FeedTheCrowdContext context, IConfiguration config) { _context = context; _config = config; }
public RecipeRepository(FeedTheCrowdContext dataContext) { _dataContext = dataContext; }
public ProductRepository(FeedTheCrowdContext context) { _dataContext = context; }
public CommentRepository(FeedTheCrowdContext dataContext) { _dataContext = dataContext; }
public UserRepository(FeedTheCrowdContext dataContext) { _dataContext = dataContext; }