Exemple #1
0
        public ActionResult DeleteTag(Recipe recipe, int TagId)
        {
            TagRecipe join = _db.TagRecipe.FirstOrDefault(recipeTag => recipeTag.TagId == TagId && recipeTag.RecipeId == recipe.RecipeId);

            _db.TagRecipe.Remove(join);
            _db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemple #2
0
        public ActionResult DeleteConfirmed(int id)
        {
            TagRecipe tagRecipe = db.TagRecipies.Find(id);

            db.TagRecipies.Remove(tagRecipe);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemple #3
0
        public ActionResult DeleteRecipe(Tag tag, int RecipeId)
        {
            TagRecipe join = _db.TagRecipe.FirstOrDefault(tagrecipe => tagrecipe.RecipeId == RecipeId && tagrecipe.TagId == tag.TagId);

            _db.TagRecipe.Remove(join);
            _db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemple #4
0
 public ActionResult Edit([Bind(Include = "RecipeId,TagId")] TagRecipe tagRecipe)
 {
     if (ModelState.IsValid)
     {
         db.Entry(tagRecipe).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.RecipeId = new SelectList(db.Recipies, "Id", "Name", tagRecipe.RecipeId);
     ViewBag.TagId    = new SelectList(db.Tags, "Id", "Name", tagRecipe.TagId);
     return(View(tagRecipe));
 }
Exemple #5
0
        public ActionResult Create([Bind(Include = "RecipeId,TagId")] TagRecipe tagRecipe)
        {
            if (ModelState.IsValid)
            {
                db.TagRecipies.Add(tagRecipe);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.RecipeId = new SelectList(db.Recipies, "Id", "Name", tagRecipe.RecipeId);
            ViewBag.TagId    = new SelectList(db.Tags, "Id", "Name", tagRecipe.TagId);
            return(View(tagRecipe));
        }
Exemple #6
0
        public ActionResult AddTag(Recipe recipe, int TagId)
        {
            TagRecipe join = _db.TagRecipe.FirstOrDefault(tagrecipe => tagrecipe.TagId == TagId && tagrecipe.RecipeId == recipe.RecipeId);

            if (TagId != 0 && join == null)
            {
                _db.TagRecipe.Add(new TagRecipe()
                {
                    TagId = TagId, RecipeId = recipe.RecipeId
                });
            }
            _db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemple #7
0
        // GET: TagRecipes/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TagRecipe tagRecipe = db.TagRecipies.Find(id);

            if (tagRecipe == null)
            {
                return(HttpNotFound());
            }
            return(View(tagRecipe));
        }
Exemple #8
0
        public ActionResult AddRecipe(Tag tag, int RecipeId)
        {
            TagRecipe join = _db.TagRecipe.FirstOrDefault(tagrecipe => tagrecipe.RecipeId == RecipeId && tagrecipe.TagId == tag.TagId);

            if (RecipeId != 0 && join == null)
            {
                _db.TagRecipe.Add(new TagRecipe()
                {
                    RecipeId = RecipeId, TagId = tag.TagId
                });
            }
            _db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemple #9
0
        // GET: TagRecipes/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TagRecipe tagRecipe = db.TagRecipies.Find(id);

            if (tagRecipe == null)
            {
                return(HttpNotFound());
            }
            ViewBag.RecipeId = new SelectList(db.Recipies, "Id", "Name", tagRecipe.RecipeId);
            ViewBag.TagId    = new SelectList(db.Tags, "Id", "Name", tagRecipe.TagId);
            return(View(tagRecipe));
        }
Exemple #10
0
        public ActionResult NewRecipe(string[] nameIngrediendRecipe, int[] countIngredienRecipe, int[] measureIdRecipe, string[] textStepRecipe, List <HttpPostedFileBase> fileInput, HttpPostedFileBase previewPhoto, string nameRecipe = "", string textRecipe = "", int hoursRecipe = 0, int minutesRecipe = 0, string tags = "")
        {
            DirectoryInfo Dir = new DirectoryInfo(Request.MapPath("~/Files/"));

            if (Dir.EnumerateDirectories().FirstOrDefault(i => i.Name == User.Identity.Name) == null)
            {
                Dir.CreateSubdirectory(User.Identity.Name);
            }

            Dir = new DirectoryInfo(Request.MapPath("~/Files/" + User.Identity.Name));
            if (Dir.EnumerateDirectories().FirstOrDefault(i => i.Name == nameRecipe) == null)
            {
                Dir.CreateSubdirectory(nameRecipe);
            }


            previewPhoto.SaveAs(Server.MapPath("~/Files/" + User.Identity.Name + "/" + nameRecipe + "/" + previewPhoto.FileName));
            Recipe recipe = new Recipe()
            {
                Hours          = hoursRecipe,
                Minutes        = minutesRecipe,
                DateOfCreation = DateTime.Now,
                Name           = nameRecipe,
                PhotoUrl       = "../Files/" + User.Identity.Name + "/" + nameRecipe + "/" + previewPhoto.FileName,
                Preview        = textRecipe,
                User           = db.Users.FirstOrDefault(i => i.Login == User.Identity.Name),
            };

            db.Recipies.Add(recipe);

            string[] arrayOfTags = tags.Split(',');
            for (int j = 0; j < arrayOfTags.Length; j++)
            {
                arrayOfTags[j] = arrayOfTags[j].Trim();
            }
            arrayOfTags = arrayOfTags.Distinct().ToArray();
            string result = "";

            for (int j = 0; j < arrayOfTags.Length - 1; j++)
            {
                var tag = arrayOfTags[j];
                result += tag;

                var tagDb = db.Tags.FirstOrDefault(i => i.Name == tag);
                if (tagDb == null)
                {
                    db.Tags.Add(new Tag {
                        Name = tag, Category = db.Categorys.FirstOrDefault(i => i.Name == "Прочее")
                    });
                }

                TagRecipe tagRecpe = new TagRecipe()
                {
                    Tag    = tagDb,
                    Recipe = recipe
                };
                db.TagRecipies.Add(tagRecpe);
            }


            for (int j = 0; j < textStepRecipe.Length; j++)
            {
                fileInput[j].SaveAs(Server.MapPath("~/Files/" + User.Identity.Name + "/" + nameRecipe + "/" + fileInput[j].FileName));
                var newStep = new Step()
                {
                    PhotoUrl = "../Files/" + User.Identity.Name + "/" + nameRecipe + "/" + fileInput[j].FileName,
                    Receipe  = recipe,
                    Text     = textStepRecipe[j]
                };
                db.Steps.Add(newStep);
            }


            for (int j = 0; j < countIngredienRecipe.Length; j++)
            {
                string name       = nameIngrediendRecipe[j];
                var    ingredient = db.Ingredients.FirstOrDefault(i => i.Name == name);
                if (ingredient == null)
                {
                    ingredient = new Ingredient()
                    {
                        Name       = nameIngrediendRecipe[j],
                        Permission = 0
                    };
                    db.Ingredients.Add(ingredient);
                }
                ;



                var newIngredient = new RecipeIngredient();

                newIngredient.Amount     = countIngredienRecipe[j];
                newIngredient.Ingredient = ingredient;
                newIngredient.Recipe     = recipe;
                newIngredient.Measure    = db.Measuries.Find(measureIdRecipe[j]);
                db.RecipeIngredients.Add(newIngredient);
            }



            db.SaveChanges();

            return(RedirectToAction("NewRecipe"));
        }