public async Task <IActionResult> Friday(int?id, string searchStudent, DateTime?TripDate = null) { var viewModel = new TripIndexData(); viewModel.Trips = await _context.Trips .Include(t => t.Bus) .Include(t => t.Driver) .ThenInclude(t => t.User) .Include(t => t.TripAssignments) .ThenInclude(t => t.Student) .ThenInclude(t => t.ParentAssignments) .ThenInclude(t => t.Parent) .Include(t => t.TripAssignments) .ThenInclude(t => t.Student) .ThenInclude(t => t.School) .AsNoTracking() .ToListAsync(); if (id != null) { ViewData["TripID"] = id.Value; Trip trip = viewModel.Trips.Where( i => i.ID == id.Value).Single(); viewModel.Students = trip.TripAssignments.Select(s => s.Student); } DateTime utcDateTime = kiwiNow.ToUniversalTime(); string nzTimeZoneKey = "New Zealand Standard Time"; TimeZoneInfo nzTimeZone = TimeZoneInfo.FindSystemTimeZoneById(nzTimeZoneKey); DateTime nzDateTime = TimeZoneInfo.ConvertTimeFromUtc(utcDateTime, nzTimeZone); var monCount = _context.Students.Where(b => b.Monday.Date >= nzDateTime.Date).Count() - _context.TripAssignments.Where(a => a.Trip.PickupTime.DayOfWeek == DayOfWeek.Monday && a.Trip.PickupTime.Date >= nzDateTime.Date).Count(); var tueCount = _context.Students.Where(b => b.Tuesday.Date >= nzDateTime.Date).Count() - _context.TripAssignments.Where(a => a.Trip.PickupTime.DayOfWeek == DayOfWeek.Tuesday && a.Trip.PickupTime.Date >= nzDateTime.Date).Count(); var wedCount = _context.Students.Where(b => b.Wednesday.Date >= nzDateTime.Date).Count() - _context.TripAssignments.Where(a => a.Trip.PickupTime.DayOfWeek == DayOfWeek.Wednesday && a.Trip.PickupTime.Date >= nzDateTime.Date).Count(); var thuCount = _context.Students.Where(b => b.Thursday.Date >= nzDateTime.Date).Count() - _context.TripAssignments.Where(a => a.Trip.PickupTime.DayOfWeek == DayOfWeek.Thursday && a.Trip.PickupTime.Date >= nzDateTime.Date).Count(); var friCount = _context.Students.Where(b => b.Friday.Date >= nzDateTime.Date).Count() - _context.TripAssignments.Where(a => a.Trip.PickupTime.DayOfWeek == DayOfWeek.Friday && a.Trip.PickupTime.Date >= nzDateTime.Date).Count(); ViewData["MonCount"] = monCount >= 0 && _context.Students.Any(c => c.Monday.Date >= nzDateTime.Date) ? monCount.ToString() : "Past"; ViewData["TueCount"] = tueCount >= 0 && _context.Students.Any(c => c.Tuesday.Date >= nzDateTime.Date) ? tueCount.ToString() : "Past"; ViewData["WedCount"] = wedCount >= 0 && _context.Students.Any(c => c.Wednesday.Date >= nzDateTime.Date) ? wedCount.ToString() : "Past"; ViewData["ThuCount"] = thuCount >= 0 && _context.Students.Any(c => c.Thursday.Date >= nzDateTime.Date) ? thuCount.ToString() : "Past"; ViewData["FriCount"] = friCount >= 0 && _context.Students.Any(c => c.Friday.Date >= nzDateTime.Date) ? friCount.ToString() : "Past"; ViewData["Drivers"] = _context.Drivers.Include(d => d.User).ToList().Distinct(); ViewData["StudentID"] = new SelectList(_context.Students.OrderBy(s => s.LastName), "Fullname", "Fullname"); var studentSchool = _context.Students .Include(g => g.School).OrderBy(g => g.School.Name).ThenBy(g => g.Fullname); ViewBag.StudentSchool = new SelectList(studentSchool, "Fullname", "Fullname", null, "School.Name"); if (!String.IsNullOrEmpty(searchStudent)) { viewModel.Trips = viewModel.Trips.Where(a => a.TripAssignments.Any(t => t.Student.Fullname.ToUpper().Contains(searchStudent.ToUpper())) && a.PickupTime.DayOfWeek == DayOfWeek.Friday); ViewData["SearchResult"] = searchStudent.ToString(); } if (TripDate != null) { viewModel.Trips = viewModel.Trips.Where(a => a.PickupTime == TripDate); ViewData["DateResult"] = TripDate.Value.ToShortDateString(); } return(View(viewModel)); }
// GET: TripAssignments public async Task <IActionResult> Index() { var viewModel = new TripIndexData(); viewModel.TripAssignments = await _context.TripAssignments .Include(t => t.Student) .ThenInclude(t => t.School) .Include(t => t.Trip) .ThenInclude(t => t.Driver) .ThenInclude(t => t.User) .AsNoTracking() .ToListAsync(); return(View(viewModel)); }
// GET: Trips public async Task <IActionResult> Index(int?id, string searchStudent, DateTime?TripDate = null) { var viewModel = new TripIndexData(); viewModel.Trips = await _context.Trips .Include(t => t.Bus) .Include(t => t.Driver) .ThenInclude(t => t.User) .Include(t => t.TripAssignments) .ThenInclude(t => t.Student) .ThenInclude(t => t.ParentAssignments) .ThenInclude(t => t.Parent) .Include(t => t.TripAssignments) .ThenInclude(t => t.Student) .ThenInclude(t => t.School) .AsNoTracking() .ToListAsync(); viewModel.TripAssignments = await _context.TripAssignments .Include(g => g.Student) .Include(g => g.Trip) .AsNoTracking() .ToListAsync(); if (id != null) { ViewData["TripID"] = id.Value; Trip trip = viewModel.Trips.Where( i => i.ID == id.Value).Single(); viewModel.Students = trip.TripAssignments.Select(s => s.Student); } DateTime utcDateTime = kiwiNow.ToUniversalTime(); string nzTimeZoneKey = "New Zealand Standard Time"; TimeZoneInfo nzTimeZone = TimeZoneInfo.FindSystemTimeZoneById(nzTimeZoneKey); DateTime nzDateTime = TimeZoneInfo.ConvertTimeFromUtc(utcDateTime, nzTimeZone); var monCount = _context.Students.Where(b => b.Monday.Date >= nzDateTime.Date).Count() - _context.TripAssignments.Where(a => a.Trip.PickupTime.DayOfWeek == DayOfWeek.Monday && a.Trip.PickupTime.Date >= nzDateTime.Date).Count(); var tueCount = _context.Students.Where(b => b.Tuesday.Date >= nzDateTime.Date).Count() - _context.TripAssignments.Where(a => a.Trip.PickupTime.DayOfWeek == DayOfWeek.Tuesday && a.Trip.PickupTime.Date >= nzDateTime.Date).Count(); var wedCount = _context.Students.Where(b => b.Wednesday.Date >= nzDateTime.Date).Count() - _context.TripAssignments.Where(a => a.Trip.PickupTime.DayOfWeek == DayOfWeek.Wednesday && a.Trip.PickupTime.Date >= nzDateTime.Date).Count(); var thuCount = _context.Students.Where(b => b.Thursday.Date >= nzDateTime.Date).Count() - _context.TripAssignments.Where(a => a.Trip.PickupTime.DayOfWeek == DayOfWeek.Thursday && a.Trip.PickupTime.Date >= nzDateTime.Date).Count(); var friCount = _context.Students.Where(b => b.Friday.Date >= nzDateTime.Date).Count() - _context.TripAssignments.Where(a => a.Trip.PickupTime.DayOfWeek == DayOfWeek.Friday && a.Trip.PickupTime.Date >= nzDateTime.Date).Count(); ViewData["MonCount"] = monCount >= 0 && _context.Students.Any(c => c.Monday.Date >= nzDateTime.Date) ? monCount.ToString() : "Past"; ViewData["TueCount"] = tueCount >= 0 && _context.Students.Any(c => c.Tuesday.Date >= nzDateTime.Date) ? tueCount.ToString() : "Past"; ViewData["WedCount"] = wedCount >= 0 && _context.Students.Any(c => c.Wednesday.Date >= nzDateTime.Date) ? wedCount.ToString() : "Past"; ViewData["ThuCount"] = thuCount >= 0 && _context.Students.Any(c => c.Thursday.Date >= nzDateTime.Date) ? thuCount.ToString() : "Past"; ViewData["FriCount"] = friCount >= 0 && _context.Students.Any(c => c.Friday.Date >= nzDateTime.Date) ? friCount.ToString() : "Past"; ViewData["Drivers"] = _context.Drivers.Include(d => d.User).ToList().Distinct(); ViewData["StudentID"] = new SelectList(_context.Students.OrderBy(s => s.LastName), "Fullname", "Fullname"); //SelectList code below contains Schoolname combined with Student name //var studentSchool = _context.Students // .Select(s => new SelectListItem // { // Value = s.Fullname, // Text = s.Fullname, // Group = new SelectListGroup { Name = s.School.Name } // }); //ViewBag.StudentSchool = new SelectList(studentSchool, "Value", "Text",4,"Group"); //SelectList code below contains Schoolname as the option group heading var studentSchool = _context.Students .Include(g => g.School).OrderBy(g => g.School.Name).ThenBy(g => g.Fullname); ViewBag.StudentSchool = new SelectList(studentSchool, "Fullname", "Fullname", null, "School.Name"); if (!String.IsNullOrEmpty(searchStudent)) { viewModel.Trips = viewModel.Trips.Where(a => a.TripAssignments.Any(t => t.Student.Fullname.ToUpper().Contains(searchStudent.ToUpper()))); ViewData["SearchResult"] = searchStudent.ToString(); } if (TripDate != null) { viewModel.Trips = viewModel.Trips.Where(a => a.PickupTime == TripDate); ViewData["DateResult"] = TripDate.Value.ToShortDateString(); } //#region School buttons that click with students listed inside ////Below is to list the students names in each school into the index view. //List<Student> studentNames = new List<Student>(); //var distinctSchools = _context.School.ToList().Distinct(new SchoolComparer()); //ViewBag.SchoolNames = distinctSchools; //viewModel.Students = await _context.Students.ToListAsync(); ////ViewData["StudentNames"] = viewModel.Students; //foreach (var schoolsDis in distinctSchools) //{ // ViewBag.SchoolNames = schoolsDis.Name; // //ViewData["StudentCount"] = schoolsDis.Students.Count; // foreach (var s in _context.Students.Where(g => g.School.Name == schoolsDis.Name)) // { // studentNames.Add(s); // } //} //ViewData["StudentNames"] = studentNames; //#endregion //if (studentID != null) //{ // ViewData["StudentID"] = studentID.Value; // var selectedStudent = viewModel.Students.Where(x => x.ID == studentID).Single(); // await _context.Entry(selectedStudent).Collection(x => x.ParentAssignments).LoadAsync(); // foreach (ParentAssignment parentAssignment in selectedStudent.ParentAssignments) // { // await _context.Entry(parentAssignment).Reference(x => x.Parent).LoadAsync(); // } // viewModel.ParentAssignments = selectedStudent.ParentAssignments; //} return(View(viewModel)); }