public AddNewRecipeVM(CategoriesDTO catRow, DirectionsDTO dirRow, DishesDTO disRow, IngredientsDTO ingRow)
 {
     Categories  = new CategoriesVM(catRow);
     Directions  = new DirectionsVM(dirRow);
     Dishes      = new DishesVM(disRow);
     Ingredients = new IngredientsVM(ingRow);
 }
        public ActionResult PhotoSlider(int id)
        {
            DishesVM      dish   = new DishesVM();
            List <string> idList = new List <string>();

            using (Db db = new Db())
            {
                DishesDTO dto = db.Dishes.Find(id);
                dish           = new DishesVM(dto);
                dish.MyGallery = Directory.EnumerateFiles(Server.MapPath("~/Content/Images/Uploads/Recipes/" + id + "/Gallery")).Select(fn => Path.GetFileName(fn));
                if (dish.MyGallery.Count() > 0)
                {
                    int i = 1;
                    foreach (var item in dish.MyGallery)
                    {
                        idList.Add("photo" + i);
                        i++;
                    }
                }
                else
                {
                }
            }

            return(PartialView(dish));
        }
        public ActionResult MyFollowingRecipes(int userId, string orderBy)
        {
            List <DishesVM> DishesList    = new List <DishesVM>();
            List <int>      followingList = new List <int>();

            using (Db db = new Db())
            {
                followingList = db.Recipe_Followers.Where(x => x.Follower_Id == userId && x.Its_Still == true).ToArray().Select(x => x.Recipe_Id).ToList();
                foreach (var item in followingList)
                {
                    DishesDTO dish = db.Dishes.Find(item);
                    DishesList.Add(new DishesVM(dish));
                }

                if (orderBy == "newest")
                {
                    DishesList = DishesList.OrderBy(x => x.Date_Added).ToList();
                }
                else if (orderBy == "mostPopular")
                {
                    DishesList.OrderBy(x => x.Rating).ToList();
                }
            }

            return(PartialView(DishesList));
        }
        public ActionResult AddNew()
        {
            List <Level> level = new List <Level>
            {
                new Level()
                {
                    Level_Id = 1, Level_Name = "Łatwy"
                },
                new Level()
                {
                    Level_Id = 2, Level_Name = "Średni"
                },
                new Level()
                {
                    Level_Id = 3, Level_Name = "Trudny"
                }
            };

            CategoriesDTO  catDTO = new CategoriesDTO();
            DirectionsDTO  dirDTO = new DirectionsDTO();
            DishesDTO      disDTO = new DishesDTO();
            IngredientsDTO ingDTO = new IngredientsDTO();
            AddNewRecipeVM model  = new AddNewRecipeVM(catDTO, dirDTO, disDTO, ingDTO);

            using (Db db = new Db())
            {
                model.Dishes.CategoriesSelectList = new SelectList(db.Categories.ToList(), "Id_Category", "Name");
                model.LevelList = new SelectList(level, "Level_Id", "Level_Name");
            }
            return(View(model));
        }
        public DishesDTO DishesGetItem(long dishIdentifier)
        {
            var dish = new DishesDTO();

            using (SqlCommand command = new SqlCommand("Usp_Dishes_GETI"))
            {
                command.Parameters.Add("@DishIdentifier", SqlDbType.BigInt).Value = dishIdentifier;
                dish = command.Select(reader => reader.ToDishes()).FirstOrDefault();
            }
            return(dish);
        }
        public ActionResult SingleRecipe(int id)
        {
            DishesVM recipeVM;

            using (Db db = new Db())
            {
                DishesDTO recipeDTO = db.Dishes.Find(id);
                recipeVM = new DishesVM(recipeDTO);
            }

            return(PartialView(recipeVM));
        }
        public bool DishSectionCreate(DishesDTO item)
        {
            bool isSectionCreated = default(bool);

            using (SqlCommand command = new SqlCommand("Usp_DishSection_INS"))
            {
                command.Parameters.Add("@DishId", SqlDbType.BigInt).Value           = item.DishIdentifier;
                command.Parameters.Add("@DishSectionName", SqlDbType.VarChar).Value = item.DishSectionsList.FirstOrDefault().DishSectionName;
                isSectionCreated = command.ExecuteQuery();
            }
            return(isSectionCreated);
        }
        public ActionResult AddPhotos(int id)
        {
            DishesVM model;

            TempData["RecipeId"] = id;

            using (Db db = new Db())
            {
                DishesDTO dish = db.Dishes.Find(id);
                model = new DishesVM(dish);
                TempData["DishName"] = model.Name;
                model.MyGallery      = Directory.EnumerateFiles(Server.MapPath("~/Content/Images/Uploads/Recipes/" + id + "/Thumbs")).Select(fn => Path.GetFileName(fn));
            }
            return(View(model));
        }
Exemplo n.º 9
0
        public void Update(DishesDTO dishDTO)
        {
            var mapper      = new MapperConfiguration(cfg => cfg.CreateMap <DishesDTO, Dish>().MaxDepth(3)).CreateMapper();
            var dishCorrect = mapper.Map <DishesDTO, Dish>(dishDTO);

            Dish dish = new Dish
            {
                Id          = dishCorrect.Id,
                Name        = dishDTO.Name,
                PrepareTime = dishCorrect.PrepareTime,
                Price       = dishCorrect.Price
            };

            Database.Dishes.Update(dish);
            Database.Save();
        }
Exemplo n.º 10
0
 public DishesVM(DishesDTO row)
 {
     Id_Dish       = row.Id_Dish;
     Id_Category   = row.Id_Category;
     Id_Direction  = row.Id_Direction;
     Id_Ingredient = row.Id_Ingredient;
     Id_Author     = row.Id_Author;
     Gallery_Path  = row.Gallery_Path;
     Name          = row.Name;
     Description   = row.Description;
     Time          = row.Time;
     Level         = row.Level;
     Servings      = row.Servings;
     Rating        = row.Rating;
     Date_Added    = row.Date_Added;
 }
        public ActionResult BestRating(string name, int userId)
        {
            List <DishesVM> DishesList = new List <DishesVM>();

            using (Db db = new Db())
            {
                if (name == "byuserid" || name == "following")
                {
                    if (name == "byuserid")
                    {
                        DishesList = db.Dishes.Where(x => x.Id_Author == userId).ToArray().Select(x => new DishesVM(x)).OrderBy(x => x.Rating).ToList();
                    }
                    else if (name == "following")
                    {
                        List <int> followingList = db.Recipe_Followers.Where(x => x.Follower_Id == userId && x.Its_Still == true).ToArray().Select(x => x.Recipe_Id).ToList();
                        foreach (var item in followingList)
                        {
                            DishesDTO dish = new DishesDTO();
                            dish = db.Dishes.First(x => x.Id_Dish == item);
                            DishesList.Add(new DishesVM(dish));
                        }
                    }
                }
                else
                {
                    if (name == "all")
                    {
                        DishesList = db.Dishes.ToArray().Select(x => new DishesVM(x)).OrderBy(x => x.Rating).Take(6).ToList();
                    }
                    else if (name != "all" && name != "byuserid")
                    {
                        CategoriesDTO category = db.Categories.FirstOrDefault(x => x.Name == name);
                        TempData["test"] = "test";
                        DishesList       = db.Dishes.Where(x => x.Id_Category == category.Id_Category).ToArray().Select(x => new DishesVM(x)).OrderBy(x => x.Rating).ToList();
                    }
                }
                foreach (var item in DishesList)
                {
                    item.MyGallery = Directory.EnumerateFiles(Server.MapPath("~/Content/Images/Uploads/Recipes/" + item.Id_Dish + "/Gallery")).Select(fn => Path.GetFileName(fn));
                }
            }

            return(PartialView(DishesList));
        }
        // GET: Recipes/Details/id
        public ActionResult Details(int id)
        {
            DishesVM recipeVM;

            TempData["categoryName"] = "";
            TempData["userName"]     = "";

            using (Db db = new Db())
            {
                DishesDTO recipeDTO = db.Dishes.Find(id);
                recipeVM = new DishesVM(recipeDTO);
                TempData["categoryName"] = db.Categories.Where(x => x.Id_Category == recipeVM.Id_Category).Select(x => x.Name).SingleOrDefault();
                recipeVM.MyGallery       = Directory.EnumerateFiles(Server.MapPath("~/Content/Images/Uploads/Recipes/" + id + "/Gallery")).Select(fn => Path.GetFileName(fn));
                TempData["bigPhoto"]     = recipeVM.MyGallery.First();
            }


            return(View(recipeVM));
        }
Exemplo n.º 13
0
        public ActionResult AddIngredient(string ingredientName, int idWhere)
        {
            //Get ingredient for name
            var            ingredientsDTO      = orderService.GetIngredient(ingredientName);
            IngredientsDTO ingredientsDTOFinal = new IngredientsDTO();
            //get dish for link in ingredient.Dishes
            DishesDTO dishesDTO = orderService.GetDishes(idWhere);

            if (ingredientsDTO == null)
            {
                ingredientsDTOFinal.Id   = orderService.GetLastIdIngredient() + 1;
                ingredientsDTOFinal.Name = ingredientName;
                ingredientsDTOFinal.Dishes.Add(dishesDTO);
                orderService.AddRefer(idWhere, ingredientsDTOFinal);
            }
            else
            {
                ingredientsDTO.Dishes.Add(dishesDTO);
                orderService.AddRefer(idWhere, ingredientsDTO);
            }

            return(Redirect("/Home/Index"));
        }
        public ActionResult AddNew(AddNewRecipeVM model, HttpPostedFileBase file)
        {
            #region Preparation-List-If-Will-Be-Errors
            List <Level> level = new List <Level>();
            level.Add(new Level()
            {
                Level_Id = 1, Level_Name = "Łatwy"
            });
            level.Add(new Level()
            {
                Level_Id = 2, Level_Name = "Średni"
            });
            level.Add(new Level()
            {
                Level_Id = 3, Level_Name = "Trudny"
            });
            using (Db db = new Db())
            {
                model.Dishes.CategoriesSelectList = new SelectList(db.Categories.ToList(), "Id_Category", "Name");
                model.LevelList = new SelectList(level, "Level_Id", "Level_Name");
            }
            #endregion

            //Exception Handling:
            #region Basic-information
            if (model.Dishes.Id_Category == 0)
            {
                TempData["WarningSection1"] = "Kategoria pozostała pusta. Uzupełnij braki i spróbuj ponownie."; return(View(model));
            }
            if (model.Dishes.Name == null)
            {
                TempData["WarningSection1"] = "Nazwa potrawy pozostała pusta. Uzupełnij braki i spróbuj ponownie."; return(View(model));
            }
            if (model.Dishes.Description == null)
            {
                TempData["WarningSection1"] = "Opis przepisu i potrawy pozostał pusty. Uzupełnij braki i spróbuj ponownie."; return(View(model));
            }
            if (model.Dishes.Servings == 0)
            {
                TempData["WarningSection1"] = "Ilość porcji pozostała pusta. Uzupełnij braki i spróbuj ponownie."; return(View(model));
            }
            if (model.Dishes.Time == null || model.Dishes.Time == "0")
            {
                TempData["WarningSection1"] = "Czas przygotowania pozostał pusty. Uzupełnij braki i spróbuj ponownie."; return(View(model));
            }
            if (model.Dishes.Level == 0)
            {
                TempData["WarningSection1"] = "Poziom trudności pozostał pusty. Uzupełnij braki i spróbuj ponownie."; return(View(model));
            }

            if (model.Dishes.Name.Length < 3)
            {
                TempData["WarningSection1"] = "Nazwa potrawy powinna składać się z co najmniej 3 znaków. Popraw błędy i spróbuj ponownie."; return(View(model));
            }
            if (model.Dishes.Description.Length < 15)
            {
                TempData["WarningSection1"] = "Opis potrawy powinna składać się z co najmniej 15 znaków. Popraw błędy i spróbuj ponownie."; return(View(model));
            }
            #endregion

            #region Ingredients-List
            if (model.Ingredients.Ingredient_1 == null)
            {
                TempData["WarningSection2"] = "Musisz dodać co najmniej jeden składnik. Uzupełnij braki i spróbuj ponownie."; return(View(model));
            }
            #endregion

            #region Direction-List
            if (model.Directions.Step_1_Content == null)
            {
                TempData["WarningSection3"] = "Musisz dodać co najmniej jeden krok przygotowania. Uzupełnij braki i spróbuj ponownie."; return(View(model));
            }
            #endregion

            //Post Method:

            int id;
            using (Db db = new Db())
            {
                #region Add-Ingredients-To-Db
                IngredientsDTO ingredients = new IngredientsDTO();
                ingredients.Ingredient_1 = model.Ingredients.Ingredient_1;

                if (model.Ingredients.Ingredient_2 != null)
                {
                    ingredients.Ingredient_2 = model.Ingredients.Ingredient_2;
                }
                else
                {
                    ingredients.Ingredient_2 = "";
                }
                if (model.Ingredients.Ingredient_3 != null)
                {
                    ingredients.Ingredient_3 = model.Ingredients.Ingredient_3;
                }
                else
                {
                    ingredients.Ingredient_3 = "";
                }
                if (model.Ingredients.Ingredient_4 != null)
                {
                    ingredients.Ingredient_4 = model.Ingredients.Ingredient_4;
                }
                else
                {
                    ingredients.Ingredient_4 = "";
                }
                if (model.Ingredients.Ingredient_5 != null)
                {
                    ingredients.Ingredient_5 = model.Ingredients.Ingredient_5;
                }
                else
                {
                    ingredients.Ingredient_5 = "";
                }
                if (model.Ingredients.Ingredient_6 != null)
                {
                    ingredients.Ingredient_6 = model.Ingredients.Ingredient_6;
                }
                else
                {
                    ingredients.Ingredient_6 = "";
                }
                if (model.Ingredients.Ingredient_7 != null)
                {
                    ingredients.Ingredient_7 = model.Ingredients.Ingredient_7;
                }
                else
                {
                    ingredients.Ingredient_7 = "";
                }
                if (model.Ingredients.Ingredient_8 != null)
                {
                    ingredients.Ingredient_8 = model.Ingredients.Ingredient_8;
                }
                else
                {
                    ingredients.Ingredient_8 = "";
                }
                if (model.Ingredients.Ingredient_9 != null)
                {
                    ingredients.Ingredient_9 = model.Ingredients.Ingredient_9;
                }
                else
                {
                    ingredients.Ingredient_9 = "";
                }
                if (model.Ingredients.Ingredient_10 != null)
                {
                    ingredients.Ingredient_10 = model.Ingredients.Ingredient_10;
                }
                else
                {
                    ingredients.Ingredient_10 = "";
                }
                if (model.Ingredients.Ingredient_11 != null)
                {
                    ingredients.Ingredient_11 = model.Ingredients.Ingredient_11;
                }
                else
                {
                    ingredients.Ingredient_11 = "";
                }
                if (model.Ingredients.Ingredient_12 != null)
                {
                    ingredients.Ingredient_12 = model.Ingredients.Ingredient_12;
                }
                else
                {
                    ingredients.Ingredient_12 = "";
                }
                if (model.Ingredients.Ingredient_13 != null)
                {
                    ingredients.Ingredient_13 = model.Ingredients.Ingredient_13;
                }
                else
                {
                    ingredients.Ingredient_13 = "";
                }
                if (model.Ingredients.Ingredient_14 != null)
                {
                    ingredients.Ingredient_14 = model.Ingredients.Ingredient_14;
                }
                else
                {
                    ingredients.Ingredient_14 = "";
                }
                if (model.Ingredients.Ingredient_15 != null)
                {
                    ingredients.Ingredient_15 = model.Ingredients.Ingredient_15;
                }
                else
                {
                    ingredients.Ingredient_15 = "";
                }

                db.Ingredients.Add(ingredients);
                #endregion

                #region Add-Directions-To-Db
                DirectionsDTO directions = new DirectionsDTO();
                directions.Step_1_Content = model.Directions.Step_1_Content;

                if (model.Directions.Step_2_Content != null)
                {
                    directions.Step_2_Content = model.Directions.Step_2_Content;
                }
                else
                {
                    directions.Step_2_Content = "";
                }
                if (model.Directions.Step_3_Content != null)
                {
                    directions.Step_3_Content = model.Directions.Step_3_Content;
                }
                else
                {
                    directions.Step_3_Content = "";
                }
                if (model.Directions.Step_4_Content != null)
                {
                    directions.Step_4_Content = model.Directions.Step_4_Content;
                }
                else
                {
                    directions.Step_4_Content = "";
                }
                if (model.Directions.Step_5_Content != null)
                {
                    directions.Step_5_Content = model.Directions.Step_5_Content;
                }
                else
                {
                    directions.Step_5_Content = "";
                }
                if (model.Directions.Step_6_Content != null)
                {
                    directions.Step_6_Content = model.Directions.Step_6_Content;
                }
                else
                {
                    directions.Step_6_Content = "";
                }
                if (model.Directions.Step_7_Content != null)
                {
                    directions.Step_7_Content = model.Directions.Step_7_Content;
                }
                else
                {
                    directions.Step_7_Content = "";
                }
                if (model.Directions.Step_8_Content != null)
                {
                    directions.Step_8_Content = model.Directions.Step_8_Content;
                }
                else
                {
                    directions.Step_8_Content = "";
                }
                if (model.Directions.Step_9_Content != null)
                {
                    directions.Step_9_Content = model.Directions.Step_9_Content;
                }
                else
                {
                    directions.Step_9_Content = "";
                }
                if (model.Directions.Step_10_Content != null)
                {
                    directions.Step_10_Content = model.Directions.Step_10_Content;
                }
                else
                {
                    directions.Step_10_Content = "";
                }

                db.Directions.Add(directions);
                #endregion

                db.SaveChanges();

                string   userName = User.Identity.Name;
                UsersDTO user     = db.Users.FirstOrDefault(x => x.Login == userName);

                DishesDTO dish = new DishesDTO
                {
                    Id_Author     = user.Id_User,
                    Id_Category   = model.Dishes.Id_Category,
                    Id_Direction  = directions.Id_Direction,
                    Id_Ingredient = ingredients.Id_Ingredient,
                    Name          = model.Dishes.Name,
                    Description   = model.Dishes.Description,
                    Servings      = model.Dishes.Servings,
                    Time          = model.Dishes.Time,
                    Level         = model.Dishes.Level,
                    Date_Added    = Convert.ToDateTime(DateTime.Today.ToString("dd-MM-yyyy"))
                };

                db.Dishes.Add(dish);
                db.SaveChanges();
                id = dish.Id_Dish;
            }

            #region Add-Gallery-Path
            var originalDirectory = new DirectoryInfo(string.Format("{0}Content\\Images\\Uploads", Server.MapPath(@"\")));
            var pathString1       = Path.Combine(originalDirectory.ToString(), "Recipes");
            var pathString2       = Path.Combine(originalDirectory.ToString(), "Recipes\\" + id.ToString());
            var pathString4       = Path.Combine(originalDirectory.ToString(), "Recipes\\" + id.ToString() + "\\Thumbs");
            var pathString3       = Path.Combine(originalDirectory.ToString(), "Recipes\\" + id.ToString() + "\\Gallery");

            if (!Directory.Exists(pathString1))
            {
                Directory.CreateDirectory(pathString1);
            }
            if (!Directory.Exists(pathString2))
            {
                Directory.CreateDirectory(pathString2);
            }
            if (!Directory.Exists(pathString3))
            {
                Directory.CreateDirectory(pathString3);
            }
            if (!Directory.Exists(pathString4))
            {
                Directory.CreateDirectory(pathString4);
            }

            using (Db db = new Db())
            {
                DishesDTO dish = new DishesDTO();
                dish = db.Dishes.Find(id);
                dish.Gallery_Path = pathString4;
                db.SaveChanges();
            }
            #endregion

            return(RedirectToAction("AddPhotos", new { id }));
        }