//[ValidateAntiForgeryToken] public JsonResult Create(Libro libro) { Ejemplar ejemplar = new Ejemplar(); String mensaje = String.Empty; try { if (ModelState.IsValid) { db.Libros.Add(libro); db.SaveChanges(); int Contador = libro.noEjemplares; for (int c=0;c<Contador;c++) { ejemplar.nombreLibro = libro.nombre; db.ejemplares.Add(ejemplar); db.SaveChanges(); } mensaje = "Se han Guardado los datos del libro satisfactoriamente"; } } catch (Exception exc) { mensaje = "Hubo un error en el servidor: " + exc.Message; } return Json(new { mensaje = mensaje }, JsonRequestBehavior.AllowGet); }
public JsonResult AjaxDelete(Libro libro) { String mensaje = String.Empty; try { db.Entry(libro).State = EntityState.Deleted; int c = db.SaveChanges(); mensaje = "Se ha eliminado libro correctamente"; } catch (Exception exc) { mensaje = "Hubo un error en el servidor: " + exc.Message; } //return Json(new { mensaje = mensaje }, JsonRequestBehavior.AllowGet); return Json("Response from Delete", JsonRequestBehavior.AllowGet); }
public JsonResult AjaxEdit(Libro libro) { String mensaje = String.Empty; try { db.Entry(libro).State = EntityState.Modified; int c = db.SaveChanges(); mensaje = "Se ha editado los datos del libro satisfactoriamente"; } catch (Exception exc) { mensaje = "Hubo un error en el servidor: " + exc.Message; } return Json(new { mensaje = mensaje }, JsonRequestBehavior.AllowGet); }