public ActionResult Edit([Bind(Include = "Id,Titulo,Autor,AnoEdicao,Valor,GeneroId")] Livro livro)
 {
     if (ModelState.IsValid)
     {
         db.Entry(livro).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.GeneroId = new SelectList(db.Generos, "Id", "Nome", livro.GeneroId);
     return(View(livro));
 }
Exemple #2
0
 public ActionResult Edit([Bind(Include = "Id,Nome")] Genero genero)
 {
     if (ModelState.IsValid)
     {
         db.Entry(genero).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(genero));
 }
 public ActionResult Edit([Bind(Include = "Id,Titulo,Autor,AnoEdicao,Valor")] Livro livro)
 {
     if (ModelState.IsValid)
     {
         db.Entry(livro).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(livro));
 }
Exemple #4
0
 public JsonResult Edit([Bind(Include = "Id,Titulo,AnoEdicao,Valor,Autor,GeneroId")] Livro livro)
 {
     if (ModelState.IsValid)
     {
         db.Entry(livro).State = EntityState.Modified;
         db.SaveChanges();
         return(Json(new { resultado = true, mensagem = "Livro editado com Sucesso" }));
     }
     else
     {
         IEnumerable <ModelError> erros = ModelState.Values.SelectMany(itens => itens.Errors);
         return(Json(new { resultado = false, mensagem = erros }));
     }
 }
        public JsonResult Edit([Bind(Include = "Id,Titulo,Autor,AnoEdicao,Valor,GeneroId")] Livro livro)
        {
            if (ModelState.IsValid)
            {
                db.Entry(livro).State = EntityState.Modified;
                db.SaveChanges();
                return(Json(new { resultado = true, mensagem = "Alterações salvas com sucesso!" }));
            }
            // else
            IEnumerable <ModelError> err = ModelState.Values.SelectMany(item => item.Errors);

            return(Json(new { resultado = false, mensagem = err }));

            /*
             * ViewBag.GeneroId = new SelectList(db.Generos, "Id", "Nome", livro.GeneroId);
             * return View(livro);*/
        }