// GET: Instructor/Details/5 public async Task <ActionResult> Details(int id) { string sql = $@" SELECT i.Id, i.FirstName, i.LastName, i.SlackHandle, i.Specialty, i.CohortId, c.Id, c.Name FROM Instructor i JOIN Cohort c ON c.Id = i.CohortId WHERE i.Id = {id} "; using (IDbConnection conn = Connection) { InstructorDetailViewModel model = new InstructorDetailViewModel(); conn.Query <Instructor, Cohort, Instructor>(sql, (generatedInstructor, generatedCohort) => { generatedInstructor.Cohort = generatedCohort; model.instructor = generatedInstructor; return(generatedInstructor); }); return(View(model)); } }
// GET: Instructor/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } InstructorDetailViewModel viewModel = new InstructorDetailViewModel(); viewModel.instructor = db.instructorModel.Find(id); if (viewModel.instructor == null) { return(HttpNotFound()); } viewModel.instructor_id = viewModel.instructor.instructor_Id; viewModel.classList = getClassList(viewModel.instructor_id); return(View(viewModel)); }
// GET: Instructor public async Task <ActionResult> Index(int?id) { var viewModel = new InstructorDetailViewModel { Instructors = await _instructorService.Get() }; if (!id.HasValue) { return(View(viewModel)); } ViewBag.InstructorId = id.Value; viewModel.Courses = viewModel.Instructors.Single(i => i.Id == id.Value).Courses; return(View(viewModel)); }
public InstructorDetails(Instructor instructor) { InitializeComponent(); BindingContext = new InstructorDetailViewModel(instructor); }
public ViewResult Detail() { InstructorDetailViewModel viewModel = new InstructorDetailViewModel(); if (Request.QueryString["instructor"] != null && StaticData.instructorList.Where(p => GlobalFunctions.escapeQuerystringElement(p.firstName + p.lastName) == GlobalFunctions.escapeQuerystringElement(Request.QueryString["instructor"].ToString())).Count() == 1) { Instructor instructor = StaticData.instructorList .Where(p => GlobalFunctions.escapeQuerystringElement(p.firstName + p.lastName) == GlobalFunctions.escapeQuerystringElement(Request.QueryString["instructor"].ToString())) .FirstOrDefault(); //Get semesters to display List <Semester> semesters = StaticData.semesters.Where(p => new SemesterComparer().Compare(p.semester, GlobalVariables.CurrentSemesterLow) >= 0 && new SemesterComparer().Compare(p.semester, GlobalVariables.CurrentSemesterHigh) <= 0).ToList(); List <CourseRating> courseRatingsOverall = CourseRatingRepositorySQL.Instance.listByInstructor(instructor.instructorID); //Get all course ratings for the instructor, and adjust to the semester range List <CourseRating> courseRatings = courseRatingsOverall .Where(p => semesters.Select(y => y.semester).Contains(p.semester)).ToList(); //Calculate number of responses and number of students var responsesOverall = courseRatingsOverall.Select(y => y.responses).Sum(z => z); var studentsOverall = courseRatingsOverall.Select(y => y.classSize).Sum(z => z); var responses = courseRatings.Select(y => y.responses).Sum(z => z); var students = courseRatings.Select(y => y.classSize).Sum(z => z); List <string> departments = new List <string>(); List <OverallRating> overallRatings = StaticData.categoryList.Where(p => p.name != "NULL").Select(p => { return(new OverallRating { category = p.name, rating = courseRatings.Sum(z => ((double)z.responses / (double)responses) * z.ratings.Where(a => a.categoryID == p.categoryID).FirstOrDefault().averageRating).ToString("#.##") }); }).ToList(); int totalResponses = 0; int totalStudents = 0; double averageRating = 0.0; List <CourseDomain> courses = StaticData.courseList.Where(p => courseRatings.Select(a => a.courseID).Distinct().Contains(p.courseID)).Select(p => { var courseRatingsList = courseRatings.Where(x => x.courseID == p.courseID); var courseResponses = courseRatingsList.Select(y => y.responses).Sum(z => z); var courseStudents = courseRatingsList.Select(y => y.classSize).Sum(z => z); var instructors = courseRatingsList.Select(y => y.instructorID).Distinct().Count(); var deptName = StaticData.departmentList.Where(u => u.departmentID == p.departmentID).FirstOrDefault().name; if (!departments.Contains(deptName)) { departments.Add(deptName); } totalResponses += courseResponses; totalStudents += courseStudents; averageRating += courseRatingsList .Sum(z => ((double)z.responses * z.ratings.Where(a => a.categoryID == Convert.ToInt32(GlobalVariables.CurrentCategory)).FirstOrDefault().averageRating)); return(new CourseDomain { code = p.code, title = p.title, departmentID = p.departmentID, departmentName = deptName, rating = courseRatingsList .Sum(z => ((double)z.responses / (double)courseResponses) * z.ratings.Where(a => a.categoryID == Convert.ToInt32(GlobalVariables.CurrentCategory)).FirstOrDefault().averageRating).ToString("#.##"), responses = courseResponses.ToString(), students = courseStudents.ToString(), responseRate = ((double)courseResponses / (double)courseStudents).ToString("p1") }); }).Where(t => Convert.ToInt32(t.students) > 0).ToList(); //Populate graph InstructorGraph instructorGraph = new InstructorGraph(); //Create a list of IEnumerables, in which each element will hold a pair, first for the semester, to sort by, second for the rating List <IEnumerable <Pair <string, string> > > graphData = new List <IEnumerable <Pair <string, string> > >(); //List of labels to display on the graph, in this case the category names List <string> labels = new List <string>(); //Loop through all categories and calculate the instructor rating for each semester for said category foreach (var category in StaticData.categoryList.Where(p => p.name != "NULL")) { graphData.Add(courseRatings.Select(p => p.semester).Distinct().Select(u => { var graphRatingsList = courseRatings.Where(x => x.semester == u); var graphResponses = graphRatingsList.Select(y => y.responses).Sum(z => z); return(new Pair <string, string>(u, graphRatingsList .Sum(z => ((double)z.responses / (double)graphResponses) * z.ratings.Where(e => e.categoryID == category.categoryID).FirstOrDefault().averageRating).ToString("#.##") )); }).OrderBy(p => p.First, new SemesterComparer()) ); labels.Add(category.name); } //Join all semesters once for the labels to be in JSON instructorGraph.labels = "['" + String.Join("', '", graphData[0].Select(p => p.First).ToArray()) + "']"; instructorGraph.data = new List <string>(); //Join the data for each linegraph to be in JSON foreach (var line in graphData) { instructorGraph.data.Add("[" + String.Join(", ", line.Select(p => p.Second).ToArray()) + "]"); } viewModel.instructor = instructor; viewModel.overallRatings = overallRatings; viewModel.courseRatingsAll = courseRatings.Select(p => { Course thisCourse = StaticData.courseList.Where(y => y.courseID == p.courseID).FirstOrDefault(); return(new CourseRatingDomain { classSize = p.classSize, courseID = p.courseID, courseRatingID = p.courseRatingID, instructorID = p.instructorID, ratings = p.ratings, responses = p.responses, section = p.section, semester = p.semester, term = p.term, courseCode = thisCourse.code }); }).ToList(); viewModel.firstTerm = courseRatingsOverall.Select(v => v.semester).Distinct() .OrderBy(t => t, new SemesterComparer()).FirstOrDefault().ToString(); viewModel.responsesAll = responsesOverall.ToString(); viewModel.studentsAll = studentsOverall.ToString(); viewModel.departments = departments; viewModel.responseRateOverall = ((double)responsesOverall / (double)studentsOverall).ToString("p1"); viewModel.courses = courses; viewModel.currentCategory = StaticData.categoryList.Where(p => p.categoryID == Convert.ToInt32(GlobalVariables.CurrentCategory)) .FirstOrDefault().name; ViewBag.loadChart = GlobalFunctions.createMultipleChartScript(instructorGraph, labels); viewModel.totalResponses = totalResponses.ToString("N0"); viewModel.totalStudents = totalStudents.ToString("N0"); viewModel.averageResponseRate = ((double)totalResponses / (double)totalStudents).ToString("p1"); viewModel.averageRating = (averageRating / (double)totalResponses).ToString("#.##"); viewModel.currentSemesterLow = GlobalVariables.CurrentSemesterLow; viewModel.currentSemesterLow = GlobalVariables.CurrentSemesterHigh; } else { throw new HttpException(404, "Instructor not found!"); } return(View(viewModel)); }