public ActionResult ManageCourseSubject()
 {
     AdminControllerCourseSubjectVM courseSubModel = new AdminControllerCourseSubjectVM();
     SubjectRepository subjectRepository = new SubjectRepository();
     CourseRepository courseRepository = new CourseRepository();
     courseSubModel.courseList = courseRepository.GetAll();
     courseSubModel.subjectList = subjectRepository.GetAll();
     return View(courseSubModel);
 }
 public ActionResult ShowCourse(int id)
 {
     AdminControllerCourseSubjectVM courseSubjectModel = new AdminControllerCourseSubjectVM();
     CourseSubjectRepository courseSubjectRepository = new CourseSubjectRepository();
     courseSubjectModel.courseSubjectList = courseSubjectRepository.GetAll();
     List<Course> courseList = new List<Course>();
     courseSubjectModel.subjectID = id;
     foreach (var item in courseSubjectModel.courseSubjectList)
     {
         if (item.Subject.Id == id)
         {
             courseList.Add(item.Course);
         }
     }
     courseSubjectModel.courseList = courseList;
     return View(courseSubjectModel);
 }
 public ActionResult EditSubjectCourse(AdminControllerCourseSubjectVM subjectCourseModel)
 {
     CourseSubject courseSubject = new CourseSubject();
     CourseSubjectRepository courseSubjectRepository = new CourseSubjectRepository();
     TryUpdateModel(subjectCourseModel);
     if (ModelState.IsValid && subjectCourseModel.CourseSubjectID > 0)
     {
         courseSubject.CourseID = subjectCourseModel.courseID;
         courseSubject.SubjectID = subjectCourseModel.subjectID;
         courseSubjectRepository.Save(courseSubject);
         return RedirectToAction("ShowCourse", "Admin", new { @id = subjectCourseModel.subjectID });
     }
     if (subjectCourseModel.ListItems == null)
     {
         List<SelectListItem> List = new List<SelectListItem>();
         CourseRepository courseRepository = new CourseRepository();
         subjectCourseModel.courseList = courseRepository.GetAll();
         foreach (var item in subjectCourseModel.courseList)
         {
             List.Add(new SelectListItem() { Text = item.Name, Value = item.Id.ToString() });
         }
         subjectCourseModel.ListItems = List;
     }
     return View(subjectCourseModel);
 }
        public ActionResult EditSubjectCourse(int id)
        {
            AdminControllerCourseSubjectVM courseSubjectModel = new AdminControllerCourseSubjectVM();
            CourseRepository courseRepository = new CourseRepository();
            courseSubjectModel.courseList = courseRepository.GetAll();

            List<SelectListItem> List = new List<SelectListItem>();
            foreach (var course in courseSubjectModel.courseList)
            {
                List.Add(new SelectListItem() { Text = course.Name, Value = course.Id.ToString() });
            }
            courseSubjectModel.ListItems = List;
            courseSubjectModel.courseList = courseRepository.GetAll();
            courseSubjectModel.subjectID = id;
            courseSubjectModel.CourseSubjectID = id;
            return View(courseSubjectModel);
        }
        public ActionResult EditCourseSubject(int courseID)
        {
            AdminControllerCourseSubjectVM courseSubjectModel = new AdminControllerCourseSubjectVM();
            SubjectRepository subjectRepository = new SubjectRepository();
            CourseSubjectRepository courseSubjectRepo = new CourseSubjectRepository();
            List<Subject> subjectList = courseSubjectRepo.GetAll(filter: cs => cs.Course.Id == courseID).Select(s => s.Subject).ToList();
            courseSubjectModel.subjectList = subjectRepository.GetAll();//Except method is overriden
            List<SelectListItem> List = new List<SelectListItem>();

            foreach (var item in courseSubjectModel.subjectList)
            {
                List.Add(new SelectListItem() { Text = item.Name, Value = item.Id.ToString() });
            }
            courseSubjectModel.ListItems = List;
            courseSubjectModel.subjectList = subjectRepository.GetAll();
            courseSubjectModel.courseID = courseID;
            courseSubjectModel.CourseSubjectID = courseID;
            return View(courseSubjectModel);
        }
        public ActionResult ShowGrades(int id, int courseSubjectID)
        {
            AdminControllerCourseSubjectVM courseSubjectModel = new AdminControllerCourseSubjectVM();
            GradeRepository gradeRepository = new GradeRepository();
            List<Grade> studentGrades = gradeRepository.GetAll(filter: s => s.Student.Id == id);

            Dictionary<string, List<Grade>> details = new Dictionary<string, List<Grade>>();
            List<string> subjectNameList = new List<string>();

            foreach (var item in studentGrades)
            {
                subjectNameList.Add(item.Subject.Name);
            }
            subjectNameList = subjectNameList.Distinct().ToList();

            foreach (var item in subjectNameList)
            {
                List<Grade> grades = new List<Grade>();
                grades = gradeRepository.GetAll(filter: s => s.Subject.Name == item && s.Student.Id == id);
                details.Add(item, grades);
            }

            courseSubjectModel.details = details;

            courseSubjectModel.StudentID = id;
            Student student = new Student();
            StudentRepository studentRepository = new StudentRepository();
            student = studentRepository.GetById(id);
            courseSubjectModel.StudentName = student.FirstName + " " + student.LastName;
            courseSubjectModel.CourseSubjectID = courseSubjectID;
            return View(courseSubjectModel);
        }
 public ActionResult ShowCourseStudents(int id)
 {
     CourseSubjectRepository courseSubjectRepository = new CourseSubjectRepository();
     AdminControllerCourseSubjectVM courseSubjectModel = new AdminControllerCourseSubjectVM();
     StudentRepository studentRepository = new StudentRepository();
     List<Student> studentList = new List<Student>();
     courseSubjectModel.CourseSubjectID = id;
     if (id > 0)
     {
         courseSubjectModel.studentList = studentRepository.GetAll(filter: s => s.CourseID == id);
     }
     return View(courseSubjectModel);
 }