public ActionResult AddStudentToClass(int studentId, int classId) { ClassStudent cs = new ClassStudent(); cs.StudentID = studentId; cs.ClassID = classId; db.ClassStudents.Add(cs); db.SaveChanges(); return RedirectToAction("Index"); }
public ActionResult ApproveAddRequest(int id) { AddRequest ar = db.AddRequests.Find(id); ar.Processed = true; ClassStudent cs = new ClassStudent(); cs.ClassID = ar.ClassID; cs.StudentID = ar.StudentID; db.ClassStudents.Add(cs); db.Entry(ar).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return RedirectToAction("ApproveAddRequest"); }
public ActionResult AddStudentToClass(int studentId, int classId) { ClassStudent check = (from m in db.ClassStudents where m.ClassID == classId && m.StudentID == studentId select m).FirstOrDefault(); if (check == null) { ClassStudent add = new ClassStudent(); add.ClassID = classId; add.StudentID = studentId; db.ClassStudents.Add(add); db.SaveChanges(); } return RedirectToAction("Index"); }