public IActionResult Edit(int id, IngredienteVM ingrediente)
        {
            if (id != ingrediente.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _service.Update(ingrediente.ToModel());
                }
                catch (Exception ex)
                {
                    if (!IngredienteExists(ingrediente.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        ViewBag.Erro = ex.Message;
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }

            return(View(ingrediente));
        }
コード例 #2
0
        public ActionResult Edit(Ingrediente ingrdnt)
        {
            ViewBag.tipoingrediente = tpingredienteService.FindAll();
            if (!ModelState.IsValid)
            {
                return(View());
            }
            bool rpta = ingredienteService.Update(ingrdnt);

            if (rpta)
            {
                return(RedirectToAction("Index"));
            }
            return(View());
        }