public ActionResult AddIngredient(IngredientModel objIngredient) { objIngredient.IngredientId = Guid.NewGuid(); ingredientRepository.AddIngredient(objIngredient); return(RedirectToAction("GetAllIngredients")); }
/// <summary> /// Method adds new ingredient to Data Base /// </summary> /// <param name="ingredient">Ingredient to add</param> public void AddIngredient(IngredientModel ingredient) { try { _ingredientRepository.AddIngredient(ingredient); } catch (Exception ex) { throw new Exception("Error while adding ingredient: " + ex.Message, ex); } }
public IActionResult Create(CreateRecipeViewModel model) { if (ModelState.IsValid) { var userId = _userManager.GetUserId(HttpContext.User); string uniqueFileName = null; if (model.Image != null) { string uploadFolder = Path.Combine("wwwroot", "images"); uniqueFileName = Guid.NewGuid().ToString() + "_" + model.Image.FileName; string filePath = Path.Combine(uploadFolder, uniqueFileName); using (var fileStream = new FileStream(filePath, FileMode.Create)) { model.Image.CopyTo(fileStream); } } Recipe newRecipe = new Recipe { Title = model.Title, Description = model.Description, Instructions = model.Instructions, MealType = model.MealType, Servings = model.Servings, PrepTime = model.PrepTime, CookTime = model.CookTime, Category = model.Category, SpiceLevel = model.SpiceLevel, ApplicationUserId = userId, ImagePath = uniqueFileName }; _recipeRepository.AddRecipe(newRecipe); foreach (var item in model.Ingredients) { Ingredient ingredient = new Ingredient { RecipeId = newRecipe.Id, Measure = item.Measure, Unit = item.Unit, Name = item.Name }; _ingredientRepository.AddIngredient(ingredient); } return(RedirectToAction("index", "home")); } return(View()); }
public ActionResult <IngredientDto> AddIngredient(IngredientForCreationDto ingredientForCreation) { var ingredient = _mapper.Map <Ingredient>(ingredientForCreation); _ingredientRepository.AddIngredient(ingredient); _ingredientRepository.Save(); var ingredientDto = _mapper.Map <IngredientDto>(ingredient); return(CreatedAtRoute("GetIngredient", new { ingredientDto.IngredientId }, ingredientDto)); }
public ActionResult Ingredients(AdminIngredientsVM model) { if (ModelState.IsValid) { //add all of the new ingredients to db foreach (var i in model.SelectedIngredients) { _ingredientRepo.AddIngredient(new Ingredient { Name = i.Name, IsLiquor = i.IsLiquor }); } return(View("Index")); } //otherwise something went wrong, send user back to view return(View("Ingredients", model)); }
public void CanAddIngredient() { _repo.AddIngredient(Mocks.mockIngredient); Assert.AreEqual(_repo.GetAllIngredients().Count, 16); }
public void AddIngredient(Ingredient ingredient) { _ingredientsRepository.AddIngredient(ingredient); }