public ActionResult AddOrEdit([Bind(Include = "GradeId,Grade1,TeacherId,StudentId")] Grade grd) { using (AjaxCRUD_DBEntities db = new AjaxCRUD_DBEntities()) { if (grd.GradeId == 0 && ModelState.IsValid) { db.Grades.Add(grd); db.SaveChanges(); } else if (grd.GradeId != 0 && ModelState.IsValid) { db.Entry(grd).State = EntityState.Modified; db.SaveChanges(); } ViewBag.StudentId = new SelectList(db.Students, "StudentId", "Name", "LastName"); ViewBag.TeacherId = new SelectList(db.Teachers, "TeacherId", "FirstName", "LastName"); } return(Json(new { success = true, html = GlobalClass.RenderRazorViewToString(this, "ViewAll", GetAllGrades()), message = "Submitted Successfully." }, JsonRequestBehavior.AllowGet)); }
public ActionResult Delete(int id) { try { using (AjaxCRUD_DBEntities db = new AjaxCRUD_DBEntities()) { Student std = db.Students.Where(x => x.StudentId == id).FirstOrDefault <Student>(); db.Students.Remove(std); db.SaveChanges(); } return(Json(new { success = true, html = GlobalClass.RenderRazorViewToString(this, "ViewAll", GetAllStudents()), message = "Deleted Successfully." }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { success = false, message = ex.Message }, JsonRequestBehavior.AllowGet)); } }
public ActionResult AddOrEdit([Bind(Include = "StudentId,FirstName,LastName,Age,UniversityId")] Student std) { using (AjaxCRUD_DBEntities db = new AjaxCRUD_DBEntities()) { if (std.StudentId == 0 && ModelState.IsValid) { db.Students.Add(std); db.SaveChanges(); } else if (std.StudentId != 0 && ModelState.IsValid) { db.Entry(std).State = EntityState.Modified; db.SaveChanges(); } ViewBag.StudentId = new SelectList(db.Universities, "UniversityId", "Name"); } return(Json(new { success = true, html = GlobalClass.RenderRazorViewToString(this, "ViewAll", GetAllStudents()), message = "Submitted Successfully." }, JsonRequestBehavior.AllowGet)); }