public ActionResult DeleteRange(int[] deleteInputs) { if (deleteInputs != null && deleteInputs.Length > 0) { for (int j = 0; j < deleteInputs.Length; j++) { int index = deleteInputs[j]; StudentMVC student = db.StudentsMVC.Find(index); db.StudentsMVC.Remove(student); var listMap = new List <StudentsManagement.Models.Mapping>(); listMap = db.Mappings.Where(i => i.StudentID == index).ToList(); var tempSub = new StudentsManagement.Models.Subject(); foreach (var item in listMap) { tempSub = db.Subjects.Find(item.SubjectID); tempSub.SubjectCurrentNumber -= 1; db.Mappings.Remove(item); } db.SaveChanges(); } } return(RedirectToAction("Index")); }
//[ValidateAntiForgeryToken] public ActionResult Edit([Bind(Include = "StudentID,StudentName,StudentAge,StudentGrade,StudentYearOfGraduation")] StudentMVC student) { if (ModelState.IsValid) { db.Entry(student).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(student)); }
public ActionResult Create([Bind(Include = "StudentID,StudentName,StudentAge,StudentGrade,StudentYearOfGraduation")] StudentMVC student) { // var student = new Student(); if (ModelState.IsValid) { db.StudentsMVC.Add(student); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(student)); }
// GET: /Student/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } StudentMVC student = db.StudentsMVC.Find(id); if (student == null) { return(HttpNotFound()); } return(View(student)); }
public ActionResult DeleteConfirmed(int id) { StudentMVC student = db.StudentsMVC.Find(id); db.StudentsMVC.Remove(student); var listMap = new List <StudentsManagement.Models.Mapping>(); listMap = db.Mappings.Where(i => i.StudentID == id).ToList(); var tempSub = new StudentsManagement.Models.Subject(); foreach (var item in listMap) { tempSub = db.Subjects.Find(item.SubjectID); tempSub.SubjectCurrentNumber -= 1; db.Mappings.Remove(item); } db.SaveChanges(); return(RedirectToAction("Index")); }