Exemplo n.º 1
0
        public ActionResult AddIngredient(IngredientModel objIngredient)
        {
            objIngredient.IngredientId = Guid.NewGuid();

            ingredientRepository.AddIngredient(objIngredient);
            return(RedirectToAction("GetAllIngredients"));
        }
Exemplo n.º 2
0
 /// <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);
     }
 }
Exemplo n.º 3
0
        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));
        }
Exemplo n.º 5
0
        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));
        }
Exemplo n.º 6
0
 public void CanAddIngredient()
 {
     _repo.AddIngredient(Mocks.mockIngredient);
     Assert.AreEqual(_repo.GetAllIngredients().Count, 16);
 }
Exemplo n.º 7
0
 public void AddIngredient(Ingredient ingredient)
 {
     _ingredientsRepository.AddIngredient(ingredient);
 }