public async Task <IActionResult> PutRecipeIngredient([FromRoute] int recipeId, [FromRoute] int ingredientId, [FromBody] RecipeIngredient recipeIngredient)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (recipeId != recipeIngredient.Recipe.Id || ingredientId != recipeIngredient.Ingredient.Id)
            {
                return(BadRequest());
            }

            _context.Entry(recipeIngredient).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RecipeIngredientExists(recipeId, ingredientId))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Beispiel #2
0
        public async Task <IActionResult> PutShoppingList([FromRoute] int id, [FromBody] ShoppingList shoppingList)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != shoppingList.Id)
            {
                return(BadRequest());
            }

            _context.Entry(shoppingList).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ShoppingListExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Beispiel #3
0
        public async Task <IActionResult> Create([Bind("Id,Name")] Store store)
        {
            if (ModelState.IsValid)
            {
                _context.Add(store);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(store));
        }
Beispiel #4
0
        public async Task <IActionResult> Create([Bind("Id,Name,StoreId")] Ingredient ingredient)
        {
            if (ModelState.IsValid)
            {
                _context.Add(ingredient);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(ingredient));
        }
Beispiel #5
0
        public async Task <IActionResult> Create([Bind("Id,Name,Description,Servings,ServingsOurs")] Recipe recipe)
        {
            if (ModelState.IsValid)
            {
                _context.Add(recipe);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(recipe));
        }
        public async Task <IActionResult> Create([Bind("ShoppingListId,RecipeId,Quantity")] ShoppingListRecipe shoppingListRecipe)
        {
            if (ModelState.IsValid)
            {
                _context.Add(shoppingListRecipe);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ShoppingListId"] = new SelectList(_context.ShoppingList, nameof(ShoppingList.Id), nameof(ShoppingList.Name), shoppingListRecipe.ShoppingListId);
            ViewData["RecipeId"]       = new SelectList(_context.Recipe, nameof(Recipe.Id), nameof(Recipe.Name), shoppingListRecipe.RecipeId);
            return(View(shoppingListRecipe));
        }
        public async Task <IActionResult> Create([Bind("RecipeId,IngredientId,Quantity,UnitId")] RecipeIngredient recipeIngredient)
        {
            if (ModelState.IsValid)
            {
                _context.Add(recipeIngredient);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["IngredientId"] = new SelectList(_context.Ingredient, nameof(Ingredient.Id), nameof(Ingredient.Name), recipeIngredient.IngredientId);
            ViewData["RecipeId"]     = new SelectList(_context.Recipe, nameof(Recipe.Id), nameof(Recipe.Name), recipeIngredient.RecipeId);
            ViewData["UnitId"]       = new SelectList(_context.Unit, nameof(Unit.Id), nameof(Unit.Name), recipeIngredient.UnitId);
            return(View(recipeIngredient));
        }
        public async Task <IHttpActionResult> Delete(int id)
        {
            using (var context = new MealsContext())
            {
                var review = await context.Reviews.FirstOrDefaultAsync(r => r.Id == id);

                if (review == null)
                {
                    return(NotFound());
                }

                context.Reviews.Remove(review);
                await context.SaveChangesAsync();
            }
            return(Ok());
        }
        public async Task <IHttpActionResult> Post([FromBody] ReviewViewModel review)
        {
            using (var context = new MealsContext())
            {
                var meal = await context.Meals.FirstOrDefaultAsync(b => b.Id == review.MealId);

                if (meal == null)
                {
                    return(NotFound());
                }

                var newReview = context.Reviews.Add(new Review
                {
                    MealId      = meal.Id,
                    Description = review.Description,
                    Rating      = review.Rating
                });

                await context.SaveChangesAsync();

                return(Ok(new ReviewViewModel(newReview)));
            }
        }