Esempio n. 1
0
        // [KeyAuthorize(PolicyEnum.User)]
        public IActionResult UpDateRecipes(int id, Recipe recipe) // metoda musi miec id i obiekt
        {
            try
            {
                if (ModelState.IsValid && CategoryExists(recipe.CategoryId))
                {
                    if (id < 0)
                    {
                        return(BadRequest());
                    }
                }
                //return NoContent();
                var item = db.Recipes.Find(id);
                if (item == null)
                {
                    return(NotFound($"Nie znaleziono id:{id}"));
                }
                item = recipe;
                db.Update(item);
                db.SaveChanges();
                return(Ok(item));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex));
            }

            //if (id < 0)
            //{
            //    return BadRequest();
            //}
            //return NoContent();
        }
        public IActionResult UpdateRecipes(int id, Recipe recipe)
        {
            try
            {
                var item = db.Recipes.Find(id);
                item = recipe;
                if (id < 0)
                {
                    return(NotFound());
                }
                db.Update(item);
                db.SaveChanges();
                return(Ok(item));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex));
            }


            //if (id < 0)
            //{
            //    return BadRequest();
            //}
            //return NoContent();
        }
Esempio n. 3
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name")] Recipe recipe)
        {
            if (id != recipe.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(recipe);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RecipeExists(recipe.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(recipe));
        }
Esempio n. 4
0
        public IActionResult UpdateRecipes(int id, Recipe recipe)
        {
            try
            {
                if (ModelState.IsValid && CategoryExists(recipe.CategoryId))
                {
                    if (id < 0)
                    {
                        return(BadRequest("id nie moze być mniejsze od 0"));
                    }
                    var recipeToUpdate = db.Recipes.Find(id);
                    if (recipeToUpdate == null)
                    {
                        return(NotFound("Nie znaleziono"));
                    }
                    recipeToUpdate = recipe;
                    db.Update(recipeToUpdate);
                    db.SaveChanges();
                    return(NoContent());
                }

                return(BadRequest("Błędne dane wejściowe"));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex));
            }
            //if (id < 0)
            //{
            //    return BadRequest();
            //}
            //return NoContent();
        }
Esempio n. 5
0
        public async Task <IActionResult> Edit(int id, [Bind("RecipeId,RecipeTitle,RecipeDescription,RecipeUploadDate,RecipeUploader,Ingredient1,Ingredient2,Ingredient3,Ingredient4,Ingredient5,Ingredient6,Ingredient7,Ingredient8,Ingredient9,Ingredient10,Ingredient11,Ingredient12,Ingredient13,Ingredient14,Ingredient15,Ingredient16,Ingredient17,Ingredient18,Ingredient19,Ingredient20,StepNumber1,Step1Description,StepNumber2,Step2Description,StepNumber3,Step3Description,StepNumber4,Step4Description,StepNumber5,Step5Description,StepNumber6,Step6Description,StepNumber7,Step7Description,StepNumber8,Step8Description,StepNumber9,Step9Description,StepNumber10,Step10Description,StepNumber11,Step11Description,StepNumber12,Step12Description,StepNumber13,Step13Description,StepNumber14,Step14Description,StepNumber15,Step15Description,StepNumber16,Step16Description,StepNumber17,Step17Description,StepNumber18,Step18Description,StepNumber19,Step19Description,StepNumber20,Step20Description")] Recipe recipe)
        {
            if (id != recipe.RecipeId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(recipe);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RecipeExists(recipe.RecipeId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(recipe));
        }
Esempio n. 6
0
 public IActionResult UpdateCategories(int id, Category category)
 {
     try
     {
         if (id < 0)
         {
             return(BadRequest("id nie moze być mniejsze od 0"));
         }
         var categoryToUpdate = db.Categories.Find(id);
         if (categoryToUpdate == null)
         {
             return(NotFound("Nie znaleziono"));
         }
         categoryToUpdate = category;
         db.Update(categoryToUpdate);
         db.SaveChanges();
         return(NoContent());
     }
     catch (Exception ex)
     {
         return(BadRequest(ex));
     }
     //if (id < 0)
     //{
     //    return BadRequest();
     //}
     //return NoContent();
 }
 public IActionResult UpdateCategory(int id, Category category)
 {
     try
     {
         var item = db.Categories.Find(id);
         item = category;
         if (id < 0)
         {
             return(NotFound());
         }
         db.Update(item);
         db.SaveChanges();
         return(Ok(item));
     }
     catch (Exception ex)
     {
         return(BadRequest(ex));
     }
 }
Esempio n. 8
0
 public void Update(Recipe recipe)
 {
     _context.Update(recipe);
 }
Esempio n. 9
0
 public async Task Update(Ingredient ingredient)
 {
     _context.Update(ingredient);
     await _context.SaveChangesAsync();
 }
Esempio n. 10
0
 public async Task Update(Recipe recipe)
 {
     _context.Update(recipe);
     await _context.SaveChangesAsync();
 }