public async Task <IActionResult> OnPostSubmitAsync() { Cadets = _context.Cadets.ToList(); if (!string.IsNullOrWhiteSpace(nameFilter)) { Cadets = Cadets.Where(s => s.Surname.Contains(nameFilter, StringComparison.CurrentCultureIgnoreCase)) .OrderBy(s => s.Surname).ToList(); } if (ageFilter != -1) { Cadets = Cadets.Where(s => s.Age == ageFilter).OrderBy(s => s.Surname).ToList(); } if (yearFilter != -1) { Cadets = Cadets.Where(s => s.Year == yearFilter).OrderBy(s => s.Surname).ToList(); } if (!string.IsNullOrWhiteSpace(formFilter)) { Cadets = Cadets.Where(s => s.Form.Contains(formFilter, StringComparison.CurrentCultureIgnoreCase)) .OrderBy(s => s.Surname).ToList(); } if (!string.IsNullOrWhiteSpace(genderFilter)) { Cadets = Cadets.Where(s => s.Gender.Contains(genderFilter, StringComparison.CurrentCultureIgnoreCase)) .OrderBy(s => s.Surname).ToList(); } if (!string.IsNullOrWhiteSpace(rankFilter)) { Cadets = Cadets.Where(s => s.Rank.Contains(rankFilter, StringComparison.CurrentCultureIgnoreCase)) .OrderBy(s => s.Surname).ToList(); } if (platoonFilter != -1) { Cadets = Cadets.Where(s => s.Platoon == platoonFilter).OrderBy(s => s.Surname).ToList(); } if (yearFilter != -1) { Cadets = Cadets.Where(s => s.Section == sectionFilter).OrderBy(s => s.Surname).ToList(); } return(Page()); }
public async Task <IActionResult> OnPostAsync() { RegisterViews = new List <RegisterView>(); Cadets = _context.Cadets.Include(c => c.Registers).OrderBy(s => s.Surname).ToList(); Registers = _context.Registers.ToList(); attFiltered = false; dayFiltered = false; compDate = daySelector(DateTime.Today.Date); if (!string.IsNullOrWhiteSpace(nameFilter)) { Cadets = Cadets.Where( s => s.Surname.Contains(nameFilter, StringComparison.CurrentCultureIgnoreCase)) .OrderBy(s => s.Surname).ToList(); } if (!string.IsNullOrWhiteSpace(attendFilter)) { if (0 == string.Compare("Yes", attendFilter, StringComparison.CurrentCultureIgnoreCase)) { attFiltered = true; filterVal = true; } if (0 == string.Compare("No", attendFilter, StringComparison.CurrentCultureIgnoreCase)) { attFiltered = true; filterVal = false; } } if (0 != DateTime.Compare(dateFilter, compDate)) { dayFiltered = true; } foreach (var cadet in Cadets) { //if no registers for a cadet, display their name if (0 == cadet.Registers.Count) { } //move data into the viewmodel else { //first reg is to only show name first time var firstRegistration = true; if (dayFiltered == true && attFiltered == true) { foreach (var register in cadet.Registers.Where(s => s.Register.DateOfReg == dateFilter && s.Register.Attended == filterVal)) { RegisterViews.Add( new RegisterView { FullName = firstRegistration ? cadet.Surname + ", " + cadet.KnownAs : "", Attendance = register.Register.Attended.ToString(), // ? "Yes" : "No", RegDate = register.Register.DateOfReg.Date, } ); firstRegistration = false; } } else if (dayFiltered == true && attFiltered == false) { foreach (var register in cadet.Registers.Where(s => s.Register.DateOfReg == dateFilter)) { RegisterViews.Add( new RegisterView { FullName = firstRegistration ? cadet.Surname + ", " + cadet.KnownAs : "", Attendance = register.Register.Attended.ToString(), // ? "Yes" : "No", RegDate = register.Register.DateOfReg.Date, } ); firstRegistration = false; } } else if (dayFiltered == false && attFiltered == true) { foreach (var register in cadet.Registers.Where(s => s.Register.Attended == filterVal)) { RegisterViews.Add( new RegisterView { FullName = firstRegistration ? cadet.Surname + ", " + cadet.KnownAs : "", Attendance = register.Register.Attended.ToString(), // ? "Yes" : "No", RegDate = register.Register.DateOfReg.Date, } ); firstRegistration = false; } } else { foreach (var register in cadet.Registers) { RegisterViews.Add( new RegisterView { FullName = firstRegistration ? cadet.Surname + ", " + cadet.KnownAs : "", Attendance = register.Register.Attended.ToString(), // ? "Yes" : "No", RegDate = register.Register.DateOfReg.Date, } ); firstRegistration = false; } } } } return(Page()); }
public async Task <IActionResult> OnPostFilterAsync() { Cadets = _context.Cadets.Include(c => c.Registers).OrderBy(s => s.Surname).ToList(); Registers = _context.Registers.ToList(); RegisterViews = new List <RegisterView>(); if (regGroup == "years") { if (regGroupVal >= 9 && regGroupVal <= 13) { Cadets = Cadets.Where(s => s.Year == regGroupVal).ToList(); } else { } } else if (regGroup == "platoons") { if (regGroupVal >= 1 && regGroupVal <= 3) { Cadets = Cadets.Where(s => s.Platoon == regGroupVal).ToList(); } else { } } else { } if (custDate == "Yes") { RegCreat(dateSel); day = dateSel; } else { day = daySelector(DateTime.Today); } for (var i = 0; i < Cadets.Count; i++)//each (var cadet in Cadets) { if (0 == Cadets[i].Registers.Count) { RegisterViews.Add( new RegisterView { FullName = Cadets[i].Surname + ", " + Cadets[i].KnownAs, Attendance = false.ToString(), RegDate = day.Date, } ); } else { for (int x = 0; x < Cadets[i].Registers.Count; x++) { if (Cadets[i].Registers[x].Register.DateOfReg == day) { RegisterViews.Add( new RegisterView { FullName = Cadets[i].Surname + ", " + Cadets[i].KnownAs, Attendance = Cadets[i].Registers[x].Register.Attended.ToString(), // ? "Yes" : "No", RegDate = day.Date, } ); regDone = true; } } if (regDone == false) { RegisterViews.Add( new RegisterView { FullName = Cadets[i].Surname + ", " + Cadets[i].KnownAs, Attendance = false.ToString(), // ? "Yes" : "No", RegDate = day.Date, } ); } } } return(Page()); }