Esempio n. 1
0
 public List <Composition> GetList()
 {
     using (var context = new CookBookContext())
     {
         return(context.Compositions.ToList());
     }
 }
Esempio n. 2
0
 public List <Ingredient> GetList()
 {
     using (var context = new CookBookContext())
     {
         return(context.Ingredients.ToList());
     }
 }
Esempio n. 3
0
 public Recipe GetItem(Guid id)
 {
     using (var context = new CookBookContext())
     {
         return(context.Recipes.FirstOrDefault(x => x.Id == id));
     }
 }
Esempio n. 4
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();


            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
                app.UseBrowserLink();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseIdentity();

            app.UseDefaultFiles();

            app.UseStaticFiles();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });

            var context = new CookBookContext();

            context.Database.Migrate();
        }
 public List <Review> GetList()
 {
     using (var context = new CookBookContext())
     {
         return(context.Reviews.ToList());
     }
 }
Esempio n. 6
0
 private void UseContext(Action <ICookBookContext> action)
 {
     using (var context = new CookBookContext(_options))
     {
         action(context);
     }
 }
 public List <User> GetList()
 {
     using (var context = new CookBookContext())
     {
         return(context.Users.ToList());
     }
 }
 public void AddRange(List <Review> items)
 {
     using (var context = new CookBookContext())
     {
         context.Reviews.AddRange(items);
         context.SaveChanges();
     }
 }
Esempio n. 9
0
 public void AddRange(List <Composition> items)
 {
     using (var context = new CookBookContext())
     {
         context.Compositions.AddRange(items);
         context.SaveChanges();
     }
 }
Esempio n. 10
0
 public void Add(Composition item)
 {
     using (var context = new CookBookContext())
     {
         context.Compositions.Add(item);
         context.SaveChanges();
     }
 }
Esempio n. 11
0
 public void AddRange(List <Ingredient> items)
 {
     using (var context = new CookBookContext())
     {
         context.Ingredients.AddRange(items);
         context.SaveChanges();
     }
 }
 public void Add(Review item)
 {
     using (var context = new CookBookContext())
     {
         context.Reviews.Add(item);
         context.SaveChanges();
     }
 }
 public void AddRange(List <User> items)
 {
     using (var context = new CookBookContext())
     {
         context.Users.AddRange(items);
         context.SaveChanges();
     }
 }
 public void Add(User item)
 {
     using (var context = new CookBookContext())
     {
         context.Users.Add(item);
         context.SaveChanges();
     }
 }
 public List <T> GetList()
 {
     using (var context = new CookBookContext())
     {
         var dbSet = context.Set <T>();
         return(dbSet.AsNoTracking().ToList());
     }
 }
Esempio n. 16
0
        public object[] BrowseRecipeSteps(int selectedRecipeId)
        {
            Console.WriteLine("Cliecked");

            using (var context = new CookBookContext())
            {
                try
                {
                    object result = context.RecipeSteps.Where(rs => rs.recipeId == selectedRecipeId).ToArray();

                    return(context.RecipeSteps.Where(rs => rs.recipeId == selectedRecipeId).ToArray());
                }
                catch (Exception e)
                {
                    Console.WriteLine("Error connecting to database: " + e.Message);
                    return(new object[] { });
                }
            }

            //using (MySqlConnection connection = GetMySqlConnection())
            //{

            //    try
            //    {
            //        connection.Open();
            //        string querySteps = "SELECT rs.stepNumber, rs.stepInstructions FROM recipes r JOIN recipe_steps rs on r.id = rs.recipeId WHERE r.id = @Id";
            //        MySqlCommand getSteps = new MySqlCommand(querySteps, connection);
            //        getSteps.Parameters.Add(new MySqlParameter("Id", selectedRecipeId));
            //        MySqlDataReader stepsReader;
            //        stepsReader = getSteps.ExecuteReader();
            //        while (stepsReader.Read())
            //        {
            //            int stepNumber = stepsReader.GetInt32(0);
            //            String stepInstruction = stepsReader.GetString(1);


            //            // create instance of RecipeStepsUIModel and add it to a list or array
            //            var recipeStep = new RecipeStepItem { stepNumber=stepNumber, stepInstruction=stepInstruction};

            //            // recipeStepList.push(recipeStep)

            //            //Console.WriteLine("Step #: {0} | Step Instruction: {1}", stepNumber, stepInstruction);



            //        }
            //        stepsReader.Close();
            //        connection.Close();

            //        return new object[] { };
            //    }
            //    catch (Exception e)
            //    {
            //        Console.WriteLine("Error connecting to database: " + e.Message);
            //        return new object[] { };
            //    }
            //}
        }
Esempio n. 17
0
 public Guid Add(Ingredient item)
 {
     using (var context = new CookBookContext())
     {
         context.Ingredients.Add(item);
         context.SaveChanges();
         return(item.Id);
     }
 }
 public void Delete(Guid id)
 {
     using (var context = new CookBookContext())
     {
         if (id != null)
         {
             context.Reviews.Remove(context.Reviews.FirstOrDefault(x => x.Id == id));
             context.SaveChanges();
         }
     }
 }
 public void Update(Review item)
 {
     using (var context = new CookBookContext())
     {
         if (item != null)
         {
             context.Entry(item).State = EntityState.Modified;
             context.SaveChanges();
         }
     }
 }
 public void AddRange(List <T> items)
 {
     using (var context = new CookBookContext())
     {
         if (items != null)
         {
             var dbSet = context.Set <T>();
             dbSet.AddRange(items);
             context.SaveChanges();
         }
     }
 }
 public void Delete(T item)
 {
     using (var context = new CookBookContext())
     {
         if (item != null)
         {
             var dbSet = context.Set <T>();
             dbSet.Remove(item);
             context.SaveChanges();
         }
     }
 }
Esempio n. 22
0
 public static IHost MigrateDatabase(this IHost host)
 {
     using (IServiceScope scope = host.Services.CreateScope())
     {
         using CookBookContext appContext = scope.ServiceProvider.GetRequiredService <CookBookContext>();
         try
         {
             appContext.Database.Migrate();
         }
         catch
         {
         }
     }
     return(host);
 }
Esempio n. 23
0
        public void TestRemoveBatchSqlProvider()
        {
            var builder = new DbContextOptionsBuilder <CookBookContext>();

            builder.UseSqlServer("Data Source=.")
            .MaxBatchSize(10)
            .CommandTimeout(10);

            using (var context = new CookBookContext(builder.Options))
            {
                var books = context.Book.ToList();

                context.RemoveRange(books.Where(e => e.Name == "Sql Batch").ToArray());

                context.SaveChanges();
            }
        }
Esempio n. 24
0
        public object[] BrowseRecipeSteps()
        {
            using (var context = new CookBookContext())
            {
                try
                {
                    object result = context.RecipeSteps.ToArray();

                    return(context.RecipeSteps.ToArray());
                }
                catch (Exception e)
                {
                    Console.WriteLine("Error connecting to database: " + e.Message);
                    return(new object[] { });
                }
            }
        }
Esempio n. 25
0
        public object[] BrowseIngredients()
        {
            using (var context = new CookBookContext())
            {
                try
                {
                    return(context.Ingredients.ToArray());
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Could not retrieve ingredients");
                    Console.WriteLine(ex.Message);

                    return(new object[] { });
                }
            }
        }
Esempio n. 26
0
        // get the RecipeIngredient from both, recipeId and ingredientId
        public object ReadRecipeIngredient(Recipe selectedRecipe, Ingredient selectedRecipeIngredient)
        {
            if (selectedRecipe == null || selectedRecipeIngredient == null)
            {
                return(false);
            }
            using (var context = new CookBookContext())
            {
                try
                {
                    return(context.RecipeIngredients.FirstOrDefault(e => (e.Id == selectedRecipe.Id && e.ingredientId == selectedRecipeIngredient.Id)));
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Could not read Recipe Ingredient");
                    Console.WriteLine(ex.Message);

                    return(null);
                }
            }
        }
Esempio n. 27
0
        public void TestBatchSqlProvider()
        {
            var builder = new DbContextOptionsBuilder <CookBookContext>();

            builder.UseSqlServer("Data Source=.")
            .MaxBatchSize(10)
            .CommandTimeout(10);

            using (var context = new CookBookContext(builder.Options))
            {
                var bookAzureSql = new Book()
                {
                    Name = "Azure Sql", Recipes = new List <Recipe>()
                };
                var bookAzureRedis = new Book()
                {
                    Name = "Azure Redis", Recipes = new List <Recipe>()
                };
                var bookSqlBatch1 = new Book()
                {
                    Name = "Sql Batch 1", Recipes = new List <Recipe>()
                };
                var bookSqlBatch2 = new Book()
                {
                    Name = "Sql Batch 2", Recipes = new List <Recipe>()
                };
                var bookSqlBatch3 = new Book()
                {
                    Name = "Sql Batch 3", Recipes = new List <Recipe>()
                };
                var bookSqlBatch4 = new Book()
                {
                    Name = "Sql Batch 4", Recipes = new List <Recipe>()
                };

                context.Book.AddRange(bookAzureSql, bookAzureRedis, bookSqlBatch1, bookSqlBatch2, bookSqlBatch3, bookSqlBatch4);

                context.SaveChanges();
            }
        }
Esempio n. 28
0
        public object ReadRecipeStep(RecipeStep recipeStep)
        {
            if (recipeStep == null)
            {
                return(false);
            }

            using (var context = new CookBookContext())
            {
                try
                {
                    return(context.RecipeSteps.FirstOrDefault(e => e.Id == recipeStep.Id || e.stepInstructions == recipeStep.stepInstructions));
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Could not read Recipe step");
                    Console.WriteLine(ex.Message);

                    return(null);
                }
            }
        }
Esempio n. 29
0
        public object ReadIngredient(Ingredient ingredient)
        {
            if (ingredient == null)
            {
                return(false);
            }

            using (var context = new CookBookContext())
            {
                try
                {
                    return(context.Ingredients.FirstOrDefault(e => e.Id == ingredient.Id || e.name == ingredient.name));
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Could not read ingredient");
                    Console.WriteLine(ex.Message);

                    return(null);
                }
            }
        }
Esempio n. 30
0
        public object ReadRecipe(Recipe recipe)
        {
            if (recipe == null)
            {
                return(false);
            }

            using (var context = new CookBookContext())
            {
                try
                {
                    return(context.Recipes.FirstOrDefault(e => e.Id == recipe.Id || e.name == recipe.name));
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Could not read recipe");
                    Console.WriteLine(ex.Message);

                    return(null);
                }
            }
        }