public ActionResult GetCourses(string Category, int?StudentID) { if (string.IsNullOrEmpty(Category)) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CoursesRepository coursesRepository = new CoursesRepository(); CourseRuleViewModel Courses = new CourseRuleViewModel(); if (StudentID == null) { //Create Request //get Courses list Courses = coursesRepository.GetCourseByCategory(Category); } else { Courses = coursesRepository.GetCourseByCategory(Category, Convert.ToInt32(StudentID)); } if (Request.IsAjaxRequest()) { return(PartialView("/Views/Students/_PartialCourseList.cshtml", Courses)); } else { return(Json(Courses, JsonRequestBehavior.AllowGet)); } }
internal CourseRuleViewModel GetCourseByCategory(string category, int StudentID) { Student student = entities.Students.Find(StudentID); if (student == null) { return(new CourseRuleViewModel()); } //student those record selected... string[] studentCourseSelected = (from selectedCourse in entities.StudentCourseMappings where (selectedCourse.StudentID == student.StudentID) select selectedCourse.CourseCode).ToArray(); var categoryRecord = (from map in entities.Courses where (studentCourseSelected.Contains(map.CousreCode)) select map).FirstOrDefault(); // List<Cours> allCoursesWithCategory = (from map in entities.Courses where (map.Category == category.Category) select map).ToList(); List <CourseViewModel> allCoursesWithCategory = (from map in entities.Courses where (map.Category == category) select new CourseViewModel { CourseID = map.CourseID, Capicity = map.Capicity, Category = map.Category, CousreCode = map.CousreCode, CourseName = map.CourseName, }).ToList(); List <CourseViewModel> selectedCourses = (from map in entities.Courses where (studentCourseSelected.Contains(map.CousreCode)) select new CourseViewModel { CourseID = map.CourseID, Capicity = map.Capicity, Category = map.Category, CousreCode = map.CousreCode, CourseName = map.CourseName, }).ToList(); foreach (CourseViewModel item in allCoursesWithCategory) { var rec = (from ss in selectedCourses where ss.CousreCode == item.CousreCode select ss.CourseID).ToList(); if (rec.Count > 0) { item.IsSelected = true; } } RulesRepository rulesRepository = new RulesRepository(); RuleViewModel ruleViewModel = rulesRepository.GetRuleDetailsByCategory(category); CourseRuleViewModel courseRuleViewModel = new CourseRuleViewModel(); courseRuleViewModel.CourseList = allCoursesWithCategory; courseRuleViewModel.Rule = ruleViewModel; return(courseRuleViewModel); }
public CourseRuleViewModel GetCourseByCategory(string Category) { RulesRepository rulesRepository = new RulesRepository(); RuleViewModel ruleViewModel = rulesRepository.GetRuleDetailsByCategory(Category); List <CourseViewModel> courseViewModels = (from course in entities.Courses select new CourseViewModel { CourseID = course.CourseID, CousreCode = course.CousreCode, CourseName = course.CourseName, Category = course.Category, Capicity = course.Capicity, }).Where(x => x.Category == Category).ToList(); CourseRuleViewModel courseRuleViewModel = new CourseRuleViewModel(); courseRuleViewModel.CourseList = courseViewModels; courseRuleViewModel.Rule = ruleViewModel; return(courseRuleViewModel); }