Beispiel #1
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());
        }
        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 #3
0
        public void AddOrUpdate(Meal meal)
        {
            var mealToSave = Context.Meals.SingleOrDefault(m => m.MealId == meal.MealId);

            if (mealToSave != null)
            {
                Context.Entry(mealToSave).CurrentValues.SetValues(meal);
            }
            else
            {
                Context.Meals.Add(meal);
            }
            Context.SaveChanges();
        }