// GET: School/InstructorCourses/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } //tblInstructorCourse tblInstructorCourse = db.tblInstructorCourses.Find(id); InstructorCourseViewModel result = (from ic in _instructorCourseRepository.GetAllInstructorCourses() join c in _courseRepository.GetAllCourses() on ic.CourseId equals c.Id join i in _instructorRepository.GetAllInstructors() on ic.InstructorId equals i.Id where ic.Id == id select new InstructorCourseViewModel { Id = ic.Id, InstructorName = i.InstructorName, CourseName = c.CourseName }).FirstOrDefault(); ViewBag.CourseId = new SelectList(_courseRepository.GetAllCourses(), "Id", "CourseName", result.CourseId); ViewBag.InstructorId = new SelectList(_instructorRepository.GetAllInstructors(), "Id", "InstructorName", result.InstructorId); return(View(result)); }
public ActionResult Edit(InstructorCourseViewModel instructorCourseViewModel) { tblInstructorCourse tic = new tblInstructorCourse(); tic.Id = instructorCourseViewModel.Id; tic.CourseId = instructorCourseViewModel.CourseId; tic.InstructorId = instructorCourseViewModel.InstructorId; _instructorCourseRepository.MySave(); return(RedirectToAction("Index")); //ViewBag.CourseId = new SelectList(db.tblCourses, "Id", "CourseName", instructorCourseViewModel.CourseId); //ViewBag.InstructorId = new SelectList(db.tblInstructors, "Id", "InstructorName", instructorCourseViewModel.InstructorId); //return View(instructorCourseViewModel); }
public ActionResult Create(InstructorCourseViewModel instructorCourseViewModel) { if (ModelState.IsValid) { tblInstructorCourse tic = new tblInstructorCourse(); tic.Id = instructorCourseViewModel.Id; tic.CourseId = instructorCourseViewModel.CourseId; tic.InstructorId = instructorCourseViewModel.InstructorId; _instructorCourseRepository.MyAdd(tic); _instructorCourseRepository.MySave(); return(RedirectToAction("Index")); } ViewBag.CourseId = new SelectList(_courseRepository.GetAllCourses(), "Id", "CourseName", instructorCourseViewModel.CourseId); ViewBag.InstructorId = new SelectList(_instructorRepository.GetAllInstructors(), "Id", "InstructorName", instructorCourseViewModel.InstructorId); return(View(instructorCourseViewModel)); }
// GET: School/InstructorCourses/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var instructorCourse = _instructorCourseRepository.GetInstructorCourseById(id); InstructorCourseViewModel result = (from ic in _instructorCourseRepository.GetAllInstructorCourses() join c in _courseRepository.GetAllCourses() on ic.CourseId equals c.Id join i in _instructorRepository.GetAllInstructors() on ic.InstructorId equals i.Id select new InstructorCourseViewModel { Id = ic.Id, InstructorName = i.InstructorName, CourseName = c.CourseName }).FirstOrDefault(); return(View(result)); }
public ActionResult ViewStudents() { var currentUserId = User.Identity.GetUserId(); var foundInstructor = db.Instrutor.Where(i => i.ApplicationUserId == currentUserId).FirstOrDefault(); var courseStudentProgressMap = new Dictionary <int, Dictionary <int, int> >(); foreach (var course in foundInstructor.Courses) { Dictionary <int, int> percentageMap = new Dictionary <int, int>(); foreach (var student in course.Students) { int completedAssignments = 0; foreach (var assignment in course.Assignments) { var progress = db.Progress.Where(p => p.AssignmentId == assignment.AssignmentId && p.StudentId == student.StudentId).FirstOrDefault(); if (progress.Status) { completedAssignments++; } } int wholePercentage = 0; if (course.Assignments.Count > 0) { wholePercentage = (completedAssignments * 100) / course.Assignments.Count(); } percentageMap.Add(student.StudentId, wholePercentage); } courseStudentProgressMap.Add(course.CourseId, percentageMap); } var model = new InstructorCourseViewModel() { Courses = foundInstructor.Courses.ToList(), CourseStudentProgress = courseStudentProgressMap }; return(View(model)); }