Exemplo n.º 1
0
        public ActionResult Like(int id)
        {
            RecipeBL recipeBL = new RecipeBL();

            recipeBL.Like(id);
            return(RedirectToAction("Przepisy"));
        }
Exemplo n.º 2
0
        public ActionResult Edit(EditVM edit)
        {
            RecipeBL recipeBL = new RecipeBL();

            HttpPostedFileBase file = Request.Files["FileUpload"];

            if (file != null && file.ContentLength > 0)
            {
                if (file.ContentType.Equals("image/jpeg") || file.ContentType.Equals("image/png"))
                {
                    //Save the File.
                    string filePath = Server.MapPath("~/Images/") + file.FileName;
                    file.SaveAs(filePath);
                    edit.Recipe.ImgName = file.FileName;
                }
                else
                {
                    ModelState.AddModelError("FormatError", "System obsługuje tylko pliki jpg i png!!");
                    return(View(edit));
                }
            }
            recipeBL.EditRecipe(edit.Recipe);

            return(RedirectToAction("UserRecipes"));
        }
Exemplo n.º 3
0
        public ActionResult Delete(int id)
        {
            RecipeBL recipe = new RecipeBL();
            DeleteVM delete = new DeleteVM();

            delete.Recipe = recipe.GetRecipes().Where(m => m.ID == id).Single();
            return(View(delete));
        }
Exemplo n.º 4
0
        public ActionResult DeletePost(int id)
        {
            RecipeBL recipeBL = new RecipeBL();
            Recipe   recipe   = new Recipe();

            recipe = recipeBL.GetRecipes().Where(m => m.ID == id).Single();
            recipeBL.DeleteRecipe(recipe);
            return(RedirectToAction("UserRecipes"));
        }
Exemplo n.º 5
0
        public ActionResult Details(int id)
        {
            RecipeBL  recipe    = new RecipeBL();
            DetailsVM detailsVM = new DetailsVM();

            detailsVM.Recipe = recipe.GetRecipes().Where(m => m.ID == id).Single();

            return(View(detailsVM));
        }
Exemplo n.º 6
0
        public ActionResult Edit(int id)
        {
            RecipeBL recipe = new RecipeBL();
            EditVM   editVM = new EditVM();

            editVM.Recipe = recipe.GetRecipes().Where(m => m.ID == id).Single();

            return(View(editVM));
        }
Exemplo n.º 7
0
        public ActionResult AddToCupboard(int id)
        {
            RecipeBL      recipeBL = new RecipeBL();
            Recipe        recipe   = recipeBL.GetRecipes().Where(m => m.ID == id).Single();
            List <Recipe> recipes  = GetSessionRecipes();

            recipes.Add(recipe);
            SaveSessionRecipes(recipes);
            return(RedirectToAction("Przepisy"));
        }
Exemplo n.º 8
0
        public ActionResult UserRecipes()
        {
            UserRecipesVM userRecipesVM = new UserRecipesVM();
            RecipeBL      recipe        = new RecipeBL();
            string        username      = HttpContext.User.Identity.Name;

            userRecipesVM.Recipes = recipe.GetUserRecipes(username);

            return(View(userRecipesVM));
        }
Exemplo n.º 9
0
        public ActionResult DeleteFromCupboard(int id)
        {
            RecipeBL      recipeBL = new RecipeBL();
            List <Recipe> recipes  = GetSessionRecipes();
            Recipe        recipe   = recipes.Where(m => m.ID == id).Single();

            recipes.Remove(recipe);
            SaveSessionRecipes(recipes);
            return(RedirectToAction("Cupboard"));
        }
Exemplo n.º 10
0
        public string IsRatedBefore(int id)
        {
            RecipeBL recipeBL = new RecipeBL();

            if (recipeBL.IsRatedBefore(id, loggedUser))
            {
                return("heart");
            }
            else
            {
                return("emptyHeart");
            }
        }
Exemplo n.º 11
0
        public int Create(RecipeBL recipe, List <CategoryRecipeBL> listOfCategories, List <SubcategoryRecipeBL> listOfSubcategories)
        {
            RatingService r        = new RatingService();
            var           ratingID = r.CreateEmptyRating();

            var recipeDAL = new Recipe()
            {
                Name            = recipe.Name,
                Description     = recipe.Description,
                LongDescription = recipe.LongDescription,
                RatingID        = ratingID,
                PictureLocation = recipe.PictureLocation,
                PrepTime        = recipe.PrepTime,
                CookTime        = recipe.CookTime
            };
            int id = recipeRepository.Create(recipeDAL);

            List <CategoryRecipe>    categoriesRecipe    = new List <CategoryRecipe>();
            List <SubcategoryRecipe> subcategoriesRecipe = new List <SubcategoryRecipe>();

            foreach (var c in listOfCategories)
            {
                categoriesRecipe.Add(new CategoryRecipe
                {
                    CategoryID = c.CategoryID,
                    RecipeID   = id
                });
            }

            foreach (var c in categoriesRecipe)
            {
                categoryRecipeRepository.Create(c);
            }

            foreach (var s in listOfSubcategories)
            {
                subcategoriesRecipe.Add(new SubcategoryRecipe
                {
                    SubcategoryID = s.SubcategoryID,
                    RecipeID      = id
                });
            }

            foreach (var s in subcategoriesRecipe)
            {
                subcategoryRecipeRepository.Create(s);
            }

            return(id);
        }
        public ActionResult Create(RecipeViewModel recipe)
        {
            RecipeBL recipeBL = new RecipeBL
            {
                Description     = recipe.Description,
                Name            = recipe.Name,
                LongDescription = recipe.LongDescription,
                PictureLocation = recipe.PictureLocation,
                PrepTime        = recipe.PrepTime,
                CookTime        = recipe.CookTime
            };

            List <CategoryRecipeBL> categories = new List <CategoryRecipeBL>();

            foreach (var i in recipe.Categories)
            {
                if (i.IsSelected == true)
                {
                    categories.Add(new CategoryRecipeBL
                    {
                        CategoryID = i.CategoryID
                    });
                }
            }

            List <SubcategoryRecipeBL> subcategories = new List <SubcategoryRecipeBL>();

            foreach (var i in recipe.Subcategories)
            {
                if (i.IsSelected == true)
                {
                    subcategories.Add(new SubcategoryRecipeBL
                    {
                        SubcategoryID = i.SubcategoryID
                    });
                }
            }
            int        id   = recipeService.Create(recipeBL, categories, subcategories);
            List <int> data = new List <int> {
                id, recipe.NrOfIngredients
            };

            return(RedirectToAction("Add", "Ingredients", new IngredientListViewModel
            {
                NrOfIngredients = recipe.NrOfIngredients,
                NrOfInstructions = recipe.NrOfInstructions,
                RecipeID = id
            }));
        }
        public ActionResult Update(RecipeViewModel recipe)
        {
            RecipeBL recipeBL = new RecipeBL
            {
                Description     = recipe.Description,
                Name            = recipe.Name,
                LongDescription = recipe.LongDescription,
                PictureLocation = recipe.PictureLocation,
                PrepTime        = recipe.PrepTime,
                CookTime        = recipe.CookTime,
                RecipeID        = recipe.RecipeID,
                RatingID        = recipe.RatingID
            };

            List <CategoryRecipeBL> categories = new List <CategoryRecipeBL>();

            foreach (var i in recipe.Categories)
            {
                if (i.IsSelected == true)
                {
                    categories.Add(new CategoryRecipeBL
                    {
                        CategoryID = i.CategoryID,
                        RecipeID   = recipe.RecipeID
                    });
                }
            }

            List <SubcategoryRecipeBL> subcategories = new List <SubcategoryRecipeBL>();

            foreach (var i in recipe.Subcategories)
            {
                if (i.IsSelected == true)
                {
                    subcategories.Add(new SubcategoryRecipeBL
                    {
                        SubcategoryID = i.SubcategoryID,
                        RecipeID      = recipe.RecipeID
                    });
                }
            }
            recipeService.Update(recipeBL, categories, subcategories);
            return(RedirectToAction("Update", "Ingredients", new IngredientListViewModel
            {
                RecipeID = recipe.RecipeID
            }));
        }
Exemplo n.º 14
0
        public RecipeBL GetRecipeByID(int id)
        {
            var recipe   = recipeRepositoryG.Get(id);
            var recipeBL = new RecipeBL()
            {
                RecipeID        = recipe.RecipeID,
                CookTime        = recipe.CookTime,
                Description     = recipe.Description,
                LongDescription = recipe.LongDescription,
                Name            = recipe.Name,
                RatingID        = recipe.RatingID,
                PictureLocation = recipe.PictureLocation,
                PrepTime        = recipe.PrepTime
            };

            return(recipeBL);
        }
 //get list of recipes in combobox
 private void GetRecipes(ComboBox cmbname)
 {
     //Recipe recipe = new Recipe(txtusername.Text);
     try
     {
         RecipeBL  recipeBL = new RecipeBL();
         DataTable dt       = recipeBL.GetRecipeListBL();
         cmbname.ItemsSource = dt.DefaultView;
         //shows the name of the recipes
         cmbname.DisplayMemberPath = dt.Columns["Name"].ToString();
         //selected value will be the recipeid
         cmbname.SelectedValuePath = dt.Columns["RecipeId"].ToString();
     }
     catch (RecipeIngredientSystemExceptions ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Exemplo n.º 16
0
        // GET: Home
        public ActionResult Przepisy()
        {
            RecipeListVM recipeListVM = new RecipeListVM();
            RecipeBL     recipeBL     = new RecipeBL();

            recipeListVM.Recipes = recipeBL.GetRecipes();

            List <Recipe> recipes = GetSessionRecipes();

            foreach (var item in recipeListVM.Recipes)
            {
                if (recipes.Any(m => m.ID == item.ID))
                {
                    item.IsInCupboard = 1;
                }
            }

            return(View(recipeListVM));
        }
        //get the selected combobox value
        private void cmbbox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            RecipeBL recipeBL = new RecipeBL();
            int      recipeid;

            try
            {
                //chack value of ComboBox
                if (cmbbox.SelectedValue != null)
                {
                    recipeid = Convert.ToInt32(cmbbox.SelectedValue);
                    //shows the details of the recipe in data grid
                    DataTable dt = recipeBL.ViewRecipeBL(recipeid);
                    grid.ItemsSource = dt.DefaultView;
                }
            }
            catch (RecipeIngredientSystemExceptions ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 18
0
        public ActionResult Create(CreateVM create)
        {
            if (ModelState.IsValid)
            {
                RecipeBL recipe = new RecipeBL();

                HttpPostedFileBase file = Request.Files["FileUpload"];



                if (file != null && file.ContentLength > 0)
                {
                    if (file.ContentType.Equals("image/jpeg") || file.ContentType.Equals("image/png"))
                    {
                        //Save the File.
                        string filePath = Server.MapPath("~/Images/") + file.FileName;
                        file.SaveAs(filePath);
                        create.Recipe.ImgName = file.FileName;
                    }
                    else
                    {
                        ModelState.AddModelError("FormatError", "System obsługuje tylko pliki jpg i png!!");
                        return(View(create));
                    }
                }
                else
                {
                    create.Recipe.ImgName = "BrakZdjecia.jpg";
                }

                create.Recipe.Username = HttpContext.User.Identity.Name;
                recipe.AddRecipe(create.Recipe);
                return(RedirectToAction("Przepisy"));
            }
            else
            {
                return(View(create));
            }
        }
Exemplo n.º 19
0
 public GraphController(AppDbContext db)
 {
     this.recipeBL = new RecipeBL(db);
 }
Exemplo n.º 20
0
        public void Update(RecipeBL recipe, List <CategoryRecipeBL> listOfCategories, List <SubcategoryRecipeBL> listOfSubcategories)
        {
            var recipeDAL = new Recipe()
            {
                Name            = recipe.Name,
                Description     = recipe.Description,
                LongDescription = recipe.LongDescription,
                RatingID        = recipe.RatingID,
                PictureLocation = recipe.PictureLocation,
                PrepTime        = recipe.PrepTime,
                CookTime        = recipe.CookTime,
                RecipeID        = recipe.RecipeID
            };

            recipeRepositoryG.Update(recipeDAL);

            List <CategoryRecipe>    categoriesRecipe    = new List <CategoryRecipe>();
            List <SubcategoryRecipe> subcategoriesRecipe = new List <SubcategoryRecipe>();

            foreach (var c in listOfCategories)
            {
                categoriesRecipe.Add(new CategoryRecipe
                {
                    CategoryID = c.CategoryID,
                    RecipeID   = recipe.RecipeID
                });
            }
            var listOfAllCategoriesForRecipe         = catRepository.GetAllCategoriesByRecipeID(recipe.RecipeID);
            List <CategoryRecipe> categoriesToInsert = new List <CategoryRecipe>();

            foreach (var c in categoriesRecipe)
            {
                if (!(listOfAllCategoriesForRecipe.Any(prod => prod.CategoryID == c.CategoryID & prod.RecipeID == c.RecipeID)))
                {
                    categoriesToInsert.Add(c);
                }
            }

            foreach (var c in listOfAllCategoriesForRecipe)
            {
                if (!(categoriesRecipe.Any(prod => prod.CategoryID == c.CategoryID & prod.RecipeID == c.RecipeID)))
                {
                    categoryRecipeRepository.Delete(c.CategoryRecipeID);
                }
            }

            foreach (var c in categoriesToInsert)
            {
                categoryRecipeRepository.Create(c);
            }


            foreach (var s in listOfSubcategories)
            {
                subcategoriesRecipe.Add(new SubcategoryRecipe
                {
                    SubcategoryID = s.SubcategoryID,
                    RecipeID      = recipe.RecipeID
                });
            }


            var listOfAllSubcategoriesForRecipe            = subcatRepository.GetAllSubCategoriesByRecipeID(recipe.RecipeID);
            List <SubcategoryRecipe> subcategoriesToInsert = new List <SubcategoryRecipe>();

            foreach (var c in subcategoriesRecipe)
            {
                if (!(listOfAllSubcategoriesForRecipe.Any(prod => prod.SubcategoryID == c.SubcategoryID & prod.RecipeID == c.RecipeID)))
                {
                    subcategoriesToInsert.Add(c);
                }
            }

            foreach (var c in listOfAllSubcategoriesForRecipe)
            {
                if (!(subcategoriesRecipe.Any(prod => prod.SubcategoryID == c.SubcategoryID & prod.RecipeID == c.RecipeID)))
                {
                    subcategoryRecipeRepository.Delete(c.SubcategoryRecipeID);
                }
            }

            foreach (var s in subcategoriesToInsert)
            {
                subcategoryRecipeRepository.Create(s);
            }
        }