// GET: Assignments public ActionResult Index() { var assignments = assignemntRepository.GetAll(); ViewBag.assignementscount = assignments.Count(); return(View(assignments)); }
// GET: Courses/Create public ActionResult Create() { AssignemntRepository assignemntRepository = new AssignemntRepository(); ViewBag.SelectedAssignmentsId = assignemntRepository.GetAll().Select(x => new SelectListItem() { Value = x.AssignmentId.ToString(), Text = x.Title }); TrainerRepository trainerRepository = new TrainerRepository(); ViewBag.SelectedTrainersId = trainerRepository.GetAll().Select(x => new SelectListItem() { Value = x.TrainerId.ToString(), Text = x.LastName }); StudentRepository studentRepository = new StudentRepository(); ViewBag.SelectedStudentsId = studentRepository.GetAll().Select(x => new SelectListItem() { Value = x.StudentId.ToString(), Text = x.LastName }); return(View()); }
// GET: Stats public ActionResult Index() { StatsViewModel svm = new StatsViewModel(); MyDatabase db = new MyDatabase(); StudentRepository studentRepository = new StudentRepository(); var students = studentRepository.GetAll(); AssignemntRepository assignemntRepository = new AssignemntRepository(); var assignments = assignemntRepository.GetAll(); TrainerRepository trainerRepository = new TrainerRepository(); var trainers = trainerRepository.GetAll(); CourseRepository courseRepository = new CourseRepository(); var courses = courseRepository.GetAll(); svm.StudentsCount = students.Count(); svm.AssignmentsCount = assignments.Count(); svm.TrainersCount = trainers.Count(); svm.CoursesCount = courses.Count(); //Grouping Course Student svm.StudentsPerCourse = students .SelectMany(x => x.Courses.Select(y => new { Key = y, Value = x })) .GroupBy(y => y.Key, x => x.Value); //Grouping Course Trainer svm.TrainersPerCourse = trainers .SelectMany(x => x.Courses.Select(y => new { Key = y, Value = x })) .GroupBy(y => y.Key, x => x.Value); //Grouping Course Assignment svm.AssignmentPerCourse = courses .SelectMany(x => x.Assignments.Select(y => new { Key = x, Value = y })) .GroupBy(y => y.Key, x => x.Value); svm.Students = students; svm.Courses = courses; svm.Assignments = assignments; return(View(svm)); }
// GET: Courses/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Course course = courseRepository.GetById(id); if (course == null) { return(HttpNotFound()); } TrainerRepository trainerRepository = new TrainerRepository(); ViewBag.SelectedTrainersId = trainerRepository.GetAll().Select(x => new SelectListItem() { Value = x.TrainerId.ToString(), Text = x.LastName, Selected = course.Trainers.Any(y => y.TrainerId == x.TrainerId) }); StudentRepository studentRepository = new StudentRepository(); ViewBag.SelectedStudentsId = studentRepository.GetAll().Select(x => new SelectListItem() { Value = x.StudentId.ToString(), Text = x.LastName, Selected = course.Students.Any(y => y.StudentId == x.StudentId) }); AssignemntRepository assignemntRepository = new AssignemntRepository(); ViewBag.SelectedAssignmentsId = assignemntRepository.GetAll().Select(x => new SelectListItem() { Value = x.AssignmentId.ToString(), Text = x.Title, Selected = course.Assignments.Any(y => y.AssignmentId == x.AssignmentId) }); return(View(course)); }