// GET: Course/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Course course = repos.GetCourse(id); if (course == null) { return(HttpNotFound()); } ViewBag.SelectedStudentsIds = stRepos.GetStudents() .Select(x => new SelectListItem() { Value = x.StudentId.ToString(), Text = string.Format("{0} {1}", x.FirstName, x.LastName) }); ViewBag.SelectedTrainersIds = trRepos.GetTrainers() .Select(x => new SelectListItem() { Value = x.TrainerId.ToString(), Text = string.Format("{0} {1}", x.FirstName, x.LastName) }); ViewBag.SelectedAssignmentsIds = asRepos.GetAssignments() .Select(x => new SelectListItem() { Value = x.AssignmentId.ToString(), Text = x.Description }); return(View(course)); }
// GET: Statistic public ActionResult Index() { var vm = new StatisticsViewModel(); vm.StudentsCount = studentRepos.GetStudents().Count(); vm.TrainersCount = trainerRepos.GetTrainers().Count(); vm.CoursesCount = courseRepos.GetCourses().Count(); vm.AssignmentsCount = assignmentRepository.GetAssignments().Count(); var courses = courseRepos.GetCourses(); var students = studentRepos.GetStudents(); var trainers = trainerRepos.GetTrainers(); var assigmnets = assignmentRepository.GetAssignments(); var studentsAssigments = studentAssignemntsrepos.GetStudentAssignments(); vm.CourseStats = courses.Where(x => x.Students != null && x.Trainers != null && x.Assignments != null); vm.StudentsByAssignments = GetStudentAssignements(); vm.MarksPerCourse = GetMarksPerCourse(); vm.MarksPerCoursePerAssignment = GetMarksPerCoursePerAssignment(); return(View(vm)); }
// GET: Trainer public ActionResult Index(string sortOrder, string firstName, string lastName, int?minSalary, int?maxSalary, int?page, int?userPageSize) { var trainers = repos.GetTrainers(); ViewBag.CurrentFirstName = firstName; ViewBag.CurrentLastName = lastName; ViewBag.CurrentMinSalary = minSalary; ViewBag.CurrentMaxSalary = maxSalary; ViewBag.PageSize = userPageSize; ViewBag.CurrentSortOrder = sortOrder; ViewBag.FirstNameSortParam = string.IsNullOrEmpty(sortOrder) ? "FirstNameDesc" : ""; ViewBag.LastNameSortParam = sortOrder == "LastNameAsc" ? "LastNameDesc" : "LastNameAsc"; ViewBag.AgeSortParam = sortOrder == "AgeAsc" ? "AgeDesc" : "AgeAsc"; ViewBag.FNView = "badge badge-primary"; ViewBag.LNView = "badge badge-primary"; ViewBag.SView = "badge badge-primary"; switch (sortOrder) { case "FirstNameDesc": trainers = trainers.OrderByDescending(x => x.FirstName); ViewBag.FNView = "badge badge-danger"; break; case "LastNameAsc": trainers = trainers.OrderBy(x => x.LastName); ViewBag.LNView = "badge badge-success"; break; case "LastNameDesc": trainers = trainers.OrderByDescending(x => x.LastName); ViewBag.LNView = "badge badge-danger"; break; case "AgeAsc": trainers = trainers.OrderBy(x => x.Salary); ViewBag.AGView = "badge badge-success"; break; case "AgeDesc": trainers = trainers.OrderByDescending(x => x.Salary); ViewBag.AGView = "badge badge-danger"; break; default: trainers = trainers.OrderBy(x => x.FirstName); ViewBag.FNView = "badge badge-success"; break; } //FirstName Filter trainers = string.IsNullOrWhiteSpace(firstName) ? trainers : trainers.Where(x => x.FirstName.ToUpper().Contains(firstName.ToUpper())); //LastName Fillter trainers = string.IsNullOrWhiteSpace(lastName) ? trainers : trainers.Where(x => x.LastName.ToUpper().Contains(lastName.ToUpper())); //MinAge Filter trainers = minSalary is null ? trainers : trainers.Where(x => x.Salary >= minSalary); //MaxAge Filter trainers = maxSalary is null ? trainers : trainers.Where(x => x.Salary <= maxSalary); //Pagination var pageSize = userPageSize ?? 3; var pageNum = page ?? 1; return(View(trainers.ToPagedList(pageNum, pageSize))); }