コード例 #1
0
        public async Task <ActionResult> MarkAsMadeIt(Recipe recipe, int id)
        {
            var userId      = this.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
            var currentUser = await _userManager.FindByIdAsync(userId);

            recipe.User = currentUser;
            Recipe thisRecipe = _db.Recipes.FirstOrDefault(recipes => recipes.RecipeId == id);

            thisRecipe.MadeIt           = true;
            _db.Entry(thisRecipe).State = EntityState.Modified;
            _db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #2
0
        public ActionResult Edit(Recipe recipe)
        {
            int ingredientNumber  = recipe.IngredientsList.Count;
            int instructionNumber = recipe.InstructionsList.Count;

            if (recipe.IngredientsGrow && recipe.InstructionsGrow)
            {
                ingredientNumber  = recipe.GrowIngredients();
                instructionNumber = recipe.GrowInstructions();
                return(Edit(recipe, ingredientNumber, instructionNumber));
            }
            else if (recipe.IngredientsGrow)
            {
                ingredientNumber = recipe.GrowIngredients();
                return(Edit(recipe, ingredientNumber, instructionNumber));
            }
            else if (recipe.InstructionsGrow)
            {
                instructionNumber = recipe.GrowInstructions();
                return(Edit(recipe, ingredientNumber, instructionNumber));
            }
            else
            {
                recipe.CleanLists();
                recipe.TranslateToString();
                _db.Entry(recipe).State = EntityState.Modified;
                _db.SaveChanges();
                return(RedirectToAction("Index"));
            }
        }
コード例 #3
0
 public ActionResult Edit(Ingredient ingredient)
 {
     if (_db.Ingredients.FirstOrDefault(ing => ing.IngredientDescription == ingredient.IngredientDescription) == null)
     {
         _db.Entry(ingredient).State = EntityState.Modified;
         _db.SaveChanges();
     }
     return(RedirectToAction("Index"));
 }
コード例 #4
0
 public ActionResult Edit([Bind(Include = "recipeID,ingredientID,amount,amountUnits")] RecipeIngredient recipeIngredient)
 {
     if (ModelState.IsValid)
     {
         db.Entry(recipeIngredient).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ingredientID = new SelectList(db.Ingredients, "ingredientID", "groceryCode", recipeIngredient.ingredientID);
     ViewBag.recipeID     = new SelectList(db.Recipes, "recipeID", "recipeName", recipeIngredient.recipeID);
     return(View(recipeIngredient));
 }
コード例 #5
0
 public ActionResult Edit(Category category, int RecipeId)
 {
     if (RecipeId != 0)
     {
         _db.CategoryRecipe.Add(new CategoryRecipe()
         {
             RecipeId = RecipeId, CategoryId = category.CategoryId
         });
     }
     _db.Entry(category).State = EntityState.Modified;
     _db.SaveChanges();
     return(RedirectToAction("Index"));
 }
コード例 #6
0
 public ActionResult Edit(Recipe recipe, int CategoryId)
 {
     if (CategoryId != 0)
     {
         _db.CategoryRecipe.Add(new CategoryRecipe()
         {
             CategoryId = CategoryId, RecipeId = recipe.RecipeId
         });
     }
     _db.Entry(recipe).State = EntityState.Modified;
     _db.SaveChanges();
     return(RedirectToAction("Index"));
 }
コード例 #7
0
 public ActionResult Edit(Tag tag, int RecipeId)
 {
     if (RecipeId != 0)
     {
         _db.RecipeTag.Add(new RecipeTag()
         {
             RecipeId = RecipeId, TagId = tag.TagId
         });
     }
     _db.Entry(tag).State = EntityState.Modified;
     _db.SaveChanges();
     return(RedirectToAction("Index"));
 }
コード例 #8
0
 public ActionResult Edit(Recipe recipe, int TagId)
 {
     if (TagId != 0)
     {
         _db.RecipeTag.Add(new RecipeTag()
         {
             TagId = TagId, RecipeId = recipe.RecipeId
         });
     }
     _db.Entry(recipe).State = EntityState.Modified;
     _db.SaveChanges();
     return(RedirectToAction("Index"));
 }
コード例 #9
0
        public ActionResult Update(Tag tag, int tagId)
        {
            bool duplicate = _db.RecipeTag.Any(recTag => recTag.TagId == tagId && recTag.TagId == tag.TagId);

            if (tagId != 0 && !duplicate)
            {
                _db.RecipeTag.Add(new RecipeTag()
                {
                    TagId = tagId, RecipeId = tag.TagId
                });
            }
            _db.Entry(tag).State = EntityState.Modified;
            _db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #10
0
        public ActionResult Edit(Recipe recipe, int CuisineId)
        {
            if (CuisineId != 0)
            {
                _db.CuisineRecipes.Add(new CuisineRecipe()
                {
                    CuisineId = CuisineId, RecipeId = recipe.RecipeId
                });
            }
            _db.Entry(recipe).State = EntityState.Modified;
            _db.SaveChanges();
            int id = recipe.RecipeId;

            return(RedirectToAction("Details", "Recipes", new { id }));
        }
コード例 #11
0
 public ActionResult Edit(Tag tag, int RecipeId)
 {
     //   var local = _db.Tags.Local.FirstOrDefault(thistag => thistag.TagId.Equals(tag.TagId));
     //   _db.Entry(local).State = EntityState.Detached;
     if (RecipeId != 0)
     {
         _db.TagRecipe.Add(new TagRecipe()
         {
             RecipeId = RecipeId, TagId = tag.TagId
         });
     }
     _db.Entry(tag).State = EntityState.Modified;
     _db.SaveChanges();
     return(RedirectToAction("Index"));
 }
コード例 #12
0
        public ActionResult Edit(Recipe recipe, int TagId)
        {
            // var existingConnection = _db.RecipeTag.FirstOrDefault(join => join.RecipeId == recipe.RecipeId && join.TagId == TagId);

            // if (existingConnection != null)
            // {
            //   return RedirectToAction("Details", new {id = recipe.RecipeId});
            // }
            if (TagId != 0)
            {
                _db.RecipeTag.Add(new RecipeTag()
                {
                    TagId = TagId, RecipeId = recipe.RecipeId
                });                                         // add to the RecipeTag database a new instance of recipetag with both the tagId and the recipeId from the recipe object passed as argument
            }
            _db.Entry(recipe).State = EntityState.Modified; // if we change an existing object, we will get errors unless we first change its entity state to modified, this is so the computer can keep track of modifications without changing the unique Ids of thes recipes
            _db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #13
0
 public ActionResult Edit(Recipe recipe, int TagId, int IngredientId)
 {
     if (TagId != 0)
     {
         _db.TagRecipe.Add(new TagRecipe()
         {
             TagId = TagId, RecipeId = recipe.RecipeId
         });
     }
     if (IngredientId != 0)
     {
         _db.IngredientRecipe.Add(new IngredientRecipe()
         {
             IngredientId = IngredientId, RecipeId = recipe.RecipeId
         });
     }
     _db.Entry(recipe).State = EntityState.Modified;
     _db.SaveChanges();
     TempData["RecipeId"] = recipe.RecipeId;
     return(RedirectToAction("Details"));
 }
コード例 #14
0
 public ActionResult Edit(Category category)
 {
     _db.Entry(category).State = EntityState.Modified;
     _db.SaveChanges();
     return(RedirectToAction("Index"));
 }
コード例 #15
0
ファイル: TagController.cs プロジェクト: juliaseid/RecipeBox
 public ActionResult Edit(Tag tag)
 {
     _db.Entry(tag).State = EntityState.Modified;
     _db.SaveChanges();
     return(RedirectToAction("Index"));
 }
コード例 #16
0
 public ActionResult Edit(Category category)           //parent is an object that contains all properties, not just the ID
 {
     _db.Entry(category).State = EntityState.Modified; // holding the information in a bucket
     _db.SaveChanges();                                // pour the bucket into the database
     return(RedirectToAction("Index"));                //returning to index page in parents
 }
コード例 #17
0
 public ActionResult Edit(Ingredient ingredient)
 {
     _db.Entry(ingredient).State = EntityState.Modified;
     _db.SaveChanges();
     return(RedirectToAction("Index"));
 }
コード例 #18
0
 public ActionResult Edit(Cuisine cuisine)
 {
     _db.Entry(cuisine).State = EntityState.Modified;
     _db.SaveChanges();
     return(RedirectToAction("Index"));
 }