Пример #1
0
        public IHttpActionResult PutContact(int id, Contact contact)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

            db.Entry(contact).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ContactExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Пример #2
0
        public async Task <IHttpActionResult> PutRecipe(int id, Recipe recipe)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != recipe.RecipeId)
            {
                return(BadRequest());
            }

            db.Entry(recipe).State = EntityState.Modified;

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Пример #3
0
        public async Task <IActionResult> UpdateRecipe(int id, Recipe recipe)
        {
            if (!ModelState.IsValid)
            {
                BadRequest(ModelState);
            }

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

            _recipes_context.Entry(recipe).State = EntityState.Modified;

            try
            {
                await _recipes_context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (RecipeExists(id))
                {
                    throw;
                }
                return(NotFound());
            }

            return(StatusCode(Convert.ToInt32(HttpStatusCode.NoContent)));
        }
        public async Task <IActionResult> PutIngredient(int id, Ingredient ingredient)
        {
            if (id != ingredient.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Пример #5
0
        public async Task <ActionResult <Recipe> > PutRecipe(Guid id, Recipe recipe)
        {
            if (id != recipe.Id)
            {
                return(BadRequest());
            }
            _context.Entry(recipe).State = EntityState.Modified;


            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!_context.Recipes.Any(e => e.Id == id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #6
0
        public async Task <ActionResult <GroceryList> > PutGroceryList(Guid id, GroceryList groceryList)
        {
            if (id != groceryList.Id)
            {
                return(BadRequest());
            }
            _context.Entry(groceryList).State = EntityState.Modified;


            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!_context.GroceryLists.Any(e => e.Id == id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Ok(groceryList));
        }
Пример #7
0
        public async Task <IActionResult> PutMenue(int id, Menue menue)
        {
            if (id != menue.MenueId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Пример #8
0
        public IHttpActionResult PutRecipes(int id, Recipes recipes)
        {
            var userID = User.Identity.GetUserId();

            recipes.UserId = userID;

            recipes.UserId = userID;

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (id != recipes.ID)
            {
                return(BadRequest());
            }



            db.Entry(recipes).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RecipesExists(recipes.ID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Пример #9
0
        public async Task <ActionResult <Recipe> > PutRecipe(long id, RecipeDto updatedRecipe)
        {
            if (id != updatedRecipe.Id)
            {
                return(BadRequest());
            }

            var currentRecipe = await _context.Recipes.FindAsync(id);

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

            currentRecipe.Name        = updatedRecipe.Name;
            currentRecipe.Description = updatedRecipe.Description;
            var ingredients        = updatedRecipe.Ingredients;
            var updatedIngredients = new List <Ingredient>();

            foreach (var ingredient in ingredients)
            {
                if (ingredient.Id == null)
                {
                    var newIngredient = new Ingredient {
                        Name   = ingredient.Name,
                        Amount = ingredient.Amount,
                        Unit   = ingredient.Unit
                    };
                    await _context.Ingredients.AddAsync(newIngredient);

                    updatedIngredients.Add(newIngredient);
                }
                else
                {
                    var updatedIngredient = await _context.Ingredients.FindAsync(ingredient.Id);

                    if (updatedIngredient == null)
                    {
                        continue;
                    }
                    updatedIngredient.Amount = ingredient.Amount;
                    updatedIngredient.Name   = ingredient.Name;
                    updatedIngredient.Unit   = ingredient.Unit;
                    updatedIngredients.Add(updatedIngredient);
                    _context.Ingredients.Update(updatedIngredient);
                }

                currentRecipe.Ingredients = updatedIngredients;
            }
            await _context.SaveChangesAsync();

            {
            }

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

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