// Update Subject Data on StudentSubjectGrade records for all students public ActionResult UpdateStudentSubjectData(int subid, int classid, int?orgid) { try { //Get all students in class to list var studs = db.StudentSubjectGrades .Where(x => x.ClassId == classid) .Where(x => x.SubjectId == subid) .Select(x => x.StudentSubjectGradeId).ToList(); //Create List var studentlist = new List <int>(studs); //Get Subject Data var subjectdata = db.Subjects.Where(s => s.ClassId == classid).Where(x => x.SubjectId == subid).FirstOrDefault(); foreach (var stud in studs) { // locate student var student = db.StudentSubjectGrades.AsNoTracking().Where(x => x.StudentSubjectGradeId == stud && x.SubjectId == subid).FirstOrDefault(); // class ref var classref = db.Classes.Where(x => x.ClassId == classid).Select(x => x.ClassRefNumb).FirstOrDefault(); var updateStudent = new StudentSubjectGrade { StudentSubjectGradeId = student.StudentSubjectGradeId, RegisteredUserId = student.RegisteredUserId, SubjectId = subid, ClassId = classid, ClassRef = classref, OrgId = orgid, FirstTerm_ExamGrade = student.FirstTerm_ExamGrade, SecondTerm_ExamGrade = student.SecondTerm_ExamGrade, ThirdTerm_ExamGrade = student.ThirdTerm_ExamGrade, FirstTerm_TestGrade = student.FirstTerm_TestGrade, SecondTerm_TestGrade = student.SecondTerm_TestGrade, ThirdTerm_TestGrade = student.ThirdTerm_TestGrade, Subject_Min_Passmark = subjectdata.Subject_Min_Passmark, Subject_Max_Passmark = subjectdata.SubjectMaxGrade, Last_updated_date = student.Last_updated_date, Created_date = student.Created_date, SubjectName = subjectdata.SubjectName, Updater_Id = student.Updater_Id, }; student = updateStudent; db.Entry(student).State = EntityState.Modified; db.SaveChanges(); } } catch (Exception e) { Console.WriteLine(e); } return(new HttpStatusCodeResult(204)); }
public ActionResult Edit(UpdateStudentGradesViewModel viewmodel) { try { foreach (var grade in viewmodel.StudentSubjectGrades) { // Locate record var grade_id = db.StudentSubjectGrades.AsNoTracking() .Where(x => x.StudentSubjectGradeId == grade.StudentSubjectGradeId).FirstOrDefault(); var rr = Session["OrgId"].ToString(); int i = Convert.ToInt32(rr); var RegisteredUserId = Convert.ToInt32(Session["RegisteredUserId"]); var updategrade = new StudentSubjectGrade { StudentSubjectGradeId = grade.StudentSubjectGradeId, RegisteredUserId = grade.RegisteredUserId, SubjectId = grade.SubjectId, ClassId = grade.ClassId, ClassRef = grade.ClassRef, OrgId = grade.OrgId, FirstTerm_ExamGrade = grade.FirstTerm_ExamGrade, SecondTerm_ExamGrade = grade.SecondTerm_ExamGrade, ThirdTerm_ExamGrade = grade.ThirdTerm_ExamGrade, FirstTerm_TestGrade = grade.FirstTerm_TestGrade, SecondTerm_TestGrade = grade.SecondTerm_TestGrade, ThirdTerm_TestGrade = grade.ThirdTerm_TestGrade, Subject_Min_Passmark = grade.Subject_Min_Passmark, Subject_Max_Passmark = grade.Subject_Max_Passmark, Last_updated_date = DateTime.Now, Created_date = grade.Created_date, SubjectName = grade.SubjectName, Updater_Id = RegisteredUserId }; grade_id = updategrade; db.Entry(grade_id).State = EntityState.Modified; db.SaveChanges(); } return(RedirectToAction("Grades")); } catch (Exception e) { Console.WriteLine(e); return(Redirect("~/ErrorHandler.html")); } }
public ActionResult AddNewSubjectToExistingStudents(int?classid, int?orgid, int subid, int?classref) { try { //Get all students in class to list var studs = db.RegisteredUsers .Where(x => x.ClassId == classid) .Select(x => x.RegisteredUserId).ToList(); //Create List var studentlist = new List <int>(studs); // Loop through students foreach (var student in studentlist) { var subjectdata = db.Subjects.Where(s => s.ClassId == classid).Where(x => x.SubjectId == subid).FirstOrDefault(); var studentsubjects = new StudentSubjectGrade() { RegisteredUserId = student, SubjectId = subid, ClassId = classid, ClassRef = classref, OrgId = orgid, FirstTerm_ExamGrade = 00.0m, SecondTerm_ExamGrade = 00.0m, ThirdTerm_ExamGrade = 00.0m, FirstTerm_TestGrade = 00.0m, SecondTerm_TestGrade = 00.0m, ThirdTerm_TestGrade = 00.0m, Last_updated_date = DateTime.Now, Created_date = DateTime.Now, SubjectName = subjectdata.SubjectName, Subject_Min_Passmark = subjectdata.Subject_Min_Passmark, Subject_Max_Passmark = subjectdata.SubjectMaxGrade, Updater_Id = 0, }; db.StudentSubjectGrades.Add(studentsubjects); db.SaveChanges(); } } catch (Exception e) { Console.WriteLine(e); } return(RedirectToAction("Index", "StudentSubjects")); }
public ActionResult CreateStudentModules(int?classid, int studid, int?classref, int i6) { try { // Locate list of subjects linked to class var subjects = db.Subjects.Where(x => x.ClassId == classid).Where(x => x.SubjectOrgId == i6).Select(x => x.SubjectId).ToList(); var listofsubjects = new List <int>(subjects); foreach (var sb in subjects) { var subjectdata = db.Subjects.Where(s => s.ClassId == classid).Where(x => x.SubjectId == sb).FirstOrDefault(); var studentsubjects = new StudentSubjectGrade() { RegisteredUserId = studid, ClassId = classid, ClassRef = classref, OrgId = i6, SubjectId = sb, SubjectName = subjectdata.SubjectName, FirstTerm_ExamGrade = 00.0m, SecondTerm_ExamGrade = 00.0m, ThirdTerm_ExamGrade = 00.0m, FirstTerm_TestGrade = 00.0m, SecondTerm_TestGrade = 00.0m, ThirdTerm_TestGrade = 00.0m, Created_date = DateTime.Now, Updater_Id = 0, Last_updated_date = DateTime.Now, Subject_Min_Passmark = subjectdata.Subject_Min_Passmark, Subject_Max_Passmark = subjectdata.SubjectMaxGrade }; db.StudentSubjectGrades.Add(studentsubjects); db.SaveChanges(); } } catch (Exception e) { Console.WriteLine(e); return(Redirect("~/ErrorHandler.html")); } return(new HttpStatusCodeResult(204)); }
public ActionResult Create(StudentSubjectGrade studentSubject) { try { if (ModelState.IsValid) { db.StudentSubjectGrades.Add(studentSubject); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.RegisteredUserId = new SelectList(db.RegisteredUsers, "RegisteredUserId", "FirstName", studentSubject.RegisteredUserId); ViewBag.SelectedSubjects = new MultiSelectList(db.Subjects, "SubjectId", "SubjectName"); ViewBag.SubjectId = new SelectList(db.Subjects, "SubjectId", "SubjectName", studentSubject.SubjectId); return(View(studentSubject)); } catch (Exception e) { Console.WriteLine(e); return(Redirect("~/ErrorHandler.html")); } }