Exemple #1
0
        public ViewResult InsertPage(RecipeFormViewModelData recipe)
        {
            if (ModelState.IsValid)
            {
                RecipeItem newRecipe = new RecipeItem();
                newRecipe.RecipeName  = recipe.RecipeName;
                newRecipe.ServingSize = recipe.ServingSize;
                newRecipe.Description = recipe.Description;
                Ingredient newIngredient = new Ingredient();
                newIngredient.IngredientName = recipe.Ingredient;
                Equipment newEquipment = new Equipment();
                newEquipment.EquipmentName = recipe.Equipment;
                newRecipe.Instructions     = recipe.Instructions;

                repository.AddRecipe(newRecipe);
                repository.AddIngredient(newIngredient);
                repository.AddEquipment(newEquipment);
                repository.AddReview(new Review());
                return(View("DataPage", repository.Recipes));
            }
            else
            {
                return(View());
            }
        }
        public async Task AddReview(Review review)
        {
            Models.Review dbReview = new Models.Review
            {
                Name        = review.Name,
                Email       = review.Email,
                Description = review.Description,
                Rating      = review.Rating,
                RecipeId    = review.RecipeId,
                CreatedDate = DateTime.Now,
                Type        = 1
            };

            await repo.AddReview(dbReview);
        }
Exemple #3
0
 public async Task <IActionResult> Post(int recipeId, Review review)
 {
     if (recipeId == review.RecipeId && _repository.RecipeExists(recipeId))
     {
         try
         {
             _repository.AddReview(review);
         }
         catch
         {
             return(BadRequest());
         }
         return(Ok());
     }
     else
     {
         return(NotFound("Recipe Id not found"));
     }
 }