public async Task <ActionResult> Create(Recipe recipe, int TagId, int IngredientId) { var userId = this.User.FindFirst(ClaimTypes.NameIdentifier)?.Value; var currentUser = await _userManager.FindByIdAsync(userId); recipe.User = currentUser; _db.Recipes.Add(recipe); 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.SaveChanges(); TempData["RecipeId"] = recipe.RecipeId; return(RedirectToAction("Details")); }
public async Task <ActionResult> Create(Recipe recipe) { int ingredientNumber = recipe.IngredientsList.Count; int instructionNumber = recipe.InstructionsList.Count; if (recipe.IngredientsGrow && recipe.InstructionsGrow) { ingredientNumber = recipe.GrowIngredients(); instructionNumber = recipe.GrowInstructions(); return(Create(recipe, ingredientNumber, instructionNumber)); } else if (recipe.IngredientsGrow) { ingredientNumber = recipe.GrowIngredients(); return(Create(recipe, ingredientNumber, instructionNumber)); } else if (recipe.InstructionsGrow) { instructionNumber = recipe.GrowInstructions(); return(Create(recipe, ingredientNumber, instructionNumber)); } else { string userId = this.User.FindFirst(ClaimTypes.NameIdentifier)?.Value; ApplicationUser currentUser = await _userManager.FindByIdAsync(userId); recipe.User = currentUser; recipe.CleanLists(); recipe.TranslateToString(); _db.Recipes.Add(recipe); _db.SaveChanges(); return(RedirectToAction("Index")); } }
public ActionResult Create(Ingredient ingredient) { if (_db.Ingredients.FirstOrDefault(ing => ing.IngredientDescription == ingredient.IngredientDescription) == null) { _db.Ingredients.Add(ingredient); _db.SaveChanges(); } return(RedirectToAction("Index")); }
public async Task <ActionResult> Create(Tag tag) { var userId = this.User.FindFirst(ClaimTypes.NameIdentifier)?.Value; var currentUser = await _userManager.FindByIdAsync(userId); tag.User = currentUser; _db.Tags.Add(tag); _db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create([Bind(Include = "recipeID,ingredientID,amount,amountUnits")] RecipeIngredient recipeIngredient) { if (ModelState.IsValid) { db.RecipeIngredients.Add(recipeIngredient); 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)); }
public ActionResult Create(Category category, int RecipeId) { _db.Categories.Add(category); if (RecipeId != 0) { _db.CategoryRecipe.Add(new CategoryRecipe() { RecipeId = RecipeId, CategoryId = category.CategoryId }); } _db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create(Tag tag, int RecipeId) { _db.Tags.Add(tag); if (RecipeId != 0) { _db.RecipeTag.Add(new RecipeTag() { RecipeId = RecipeId, TagId = tag.TagId }); } _db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create(Tag tag, List <int> RecipeId) { _db.Tags.Add(tag); if (RecipeId.Count != 0) { foreach (int Recipe in RecipeId) { _db.TagRecipe.Add(new TagRecipe() { RecipeId = Recipe, TagId = tag.TagId }); } } _db.SaveChanges(); return(RedirectToAction("Index")); }
public async Task <ActionResult> Create(Recipe recipe, int CategoryId) { var userId = this.User.FindFirst(ClaimTypes.NameIdentifier)?.Value; var currentUser = await _userManager.FindByIdAsync(userId); recipe.User = currentUser; _db.Recipes.Add(recipe); if (CategoryId != 0) { _db.CategoryRecipe.Add(new CategoryRecipe() { CategoryId = CategoryId, RecipeId = recipe.RecipeId }); } _db.SaveChanges(); return(RedirectToAction("Index")); }
public async Task <ActionResult> Create(Recipe recipe, int CuisineId) { var userId = this.User.FindFirst(ClaimTypes.NameIdentifier)?.Value; var currentUser = await _userManager.FindByIdAsync(userId); recipe.User = currentUser; _db.Recipes.Add(recipe); //this actually adds user input to DB without needing a migration or an update. if (CuisineId != 0) { _db.CuisineRecipes.Add(new CuisineRecipe() { CuisineId = CuisineId, RecipeId = recipe.RecipeId }); } _db.SaveChanges(); return(RedirectToAction("Index")); }
public async Task <ActionResult> Create(Tag tag, int RecipeId) { var userId = this.User.FindFirst(ClaimTypes.NameIdentifier)?.Value; var currentUser = await _userManager.FindByIdAsync(userId); tag.User = currentUser; _db.Tags.Add(tag); if (RecipeId != 0) { _db.RecipeTag.Add(new RecipeTag() { RecipeId = RecipeId, TagId = tag.TagId }); } _db.SaveChanges(); return(RedirectToAction("Index")); }
public async Task <ActionResult> Create(Recipe recipe, List <int> IngredientId, List <int> TagId) { var userId = this.User.FindFirst(ClaimTypes.NameIdentifier)?.Value; var currentUser = await _userManager.FindByIdAsync(userId); recipe.User = currentUser; _db.Recipes.Add(recipe); if (IngredientId.Count != 0) { foreach (int Ingredient in IngredientId) { _db.RecipeIngredient.Add(new RecipeIngredient() { IngredientId = Ingredient, RecipeId = recipe.RecipeId }); } } if (TagId.Count != 0) { foreach (int Tag in TagId) { _db.TagRecipe.Add(new TagRecipe() { TagId = Tag, RecipeId = recipe.RecipeId }); } } _db.SaveChanges(); return(RedirectToAction("Index")); }
public async Task <ActionResult> Create(Recipe recipe, int TagId) { string userId = this.User.FindFirst(ClaimTypes.NameIdentifier)?.Value; ApplicationUser currentUser = await _userManager.FindByIdAsync(userId); recipe.User = currentUser; _db.Recipes.Add(recipe); if (TagId != 0) { _db.RecipeTag.Add(new RecipeTag() { TagId = TagId, RecipeId = recipe.RecipeId }); } _db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create(Recipe recipe) { try { // TODO: Add insert logic here if (ModelState.IsValid) { _db.Recipes.Add(recipe); _db.SaveChanges(); return(Redirect("~/RecipeIngredients/Create?")); } return(View(recipe)); } catch { return(View()); } }
public async Task <ActionResult> Create(Recipe recipe, int TagId) { var userId = this.User.FindFirst(ClaimTypes.NameIdentifier)?.Value; // if condition to the left of '?' is true, then get the value and save as userId variable var currentUser = await _userManager.FindByIdAsync(userId); // use user manager to grab user object by the user id that we created on the liine above. recipe.User = currentUser; _db.Recipes.Add(recipe); if (TagId != 0) { _db.RecipeTag.Add(new RecipeTag() { TagId = TagId, RecipeId = recipe.RecipeId }); } _db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create(Category category) { _db.Categories.Add(category); _db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create(Tag tag) { _db.Tags.Add(tag); _db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create(Ingredient ingredient) { _db.Ingredients.Add(ingredient); _db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create(Cuisine cuisine) { _db.Cuisines.Add(cuisine); _db.SaveChanges(); return(RedirectToAction("Index")); }