public async Task <IActionResult> OnPostAsync() { if (Request.Form["type"] == "start") { Hearings = await _context.Hearings .Include(h => h.Case) .Include(h => h.Department) .OrderBy(h => h.Number) .ThenBy(h => h.DateTime) .ThenBy(h => h.Type) .ThenBy(h => h.Case.Number).ToListAsync(); Departments = await _context.Departments .OrderBy(d => d.Name).ToListAsync(); foreach (Department department in Departments) { DateTime CurrentDateTime = DateTime.MinValue; int HearingNumber = 0; foreach (Hearing hearing in Hearings) { if (hearing.Department != department) { continue; } if (CurrentDateTime != hearing.DateTime) { CurrentDateTime = hearing.DateTime; HearingNumber = (TimeSlots.Times.IndexOf(hearing.DateTime.ToString("t")) + 1) * 1000; } hearing.Number = HearingNumber; HearingNumber++; } } } else if (Request.Form["type"] == "reset") { foreach (Hearing hearing in _context.Hearings) { hearing.Number = null; } } await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } Hearings = await _context.Hearings .Include(h => h.Case) .Include(h => h.Department) .OrderBy(h => h.Number) .ThenBy(h => h.DateTime) .ThenBy(h => h.Type) .ThenBy(h => h.Case.Number).ToListAsync(); if (Hearings[0].Number != null) { DateTime CurrentDateTime = DateTime.MinValue; int HearingNumber = (TimeSlots.Times.IndexOf(NewHearing.DateTime.ToString("t")) + 1) * 1000; foreach (Hearing h in Hearings) { if (h.DepartmentId != NewHearing.DepartmentId) { continue; } if (h.Number > HearingNumber) { break; } else if (h.Number == HearingNumber) { HearingNumber++; } } NewHearing.Number = HearingNumber; } _context.Hearings.Add(NewHearing); await _context.SaveChangesAsync(); return(RedirectToPage("Index")); }