示例#1
0
        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++;
                    }
                }
            }
        }
示例#2
0
        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();
        }
示例#3
0
 public AuthRepository(FeedTheCrowdContext context, IConfiguration config)
 {
     _context = context;
     _config  = config;
 }
示例#4
0
 public RecipeRepository(FeedTheCrowdContext dataContext)
 {
     _dataContext = dataContext;
 }
示例#5
0
 public ProductRepository(FeedTheCrowdContext context)
 {
     _dataContext = context;
 }
示例#6
0
 public CommentRepository(FeedTheCrowdContext dataContext)
 {
     _dataContext = dataContext;
 }
示例#7
0
 public UserRepository(FeedTheCrowdContext dataContext)
 {
     _dataContext = dataContext;
 }