//Display list of staff currently not allocated to event, based on event id provided //Staff can be added or removed in bulk in this view via ajax public async Task <IActionResult> Create(int eventId) { int numGuests = (await _context.Guests.Include(g => g.Event).Where(g => g.EventId == eventId).ToListAsync()).Count(); var unavailableStaff = await _context.Staffing.Include(g => g.Staff).Where(g => g.EventId == eventId).ToListAsync(); var unStaff = await _context.Staff.Where(e => unavailableStaff.Any(a => a.StaffId.Equals(e.Id))).OrderBy(e => e.Id).ToListAsync(); var staff = await _context.Staff.Except(unStaff).ToListAsync(); bool firstAiderPresent = false; foreach (Staff s in unStaff) { if (firstAiderPresent == false && s.FirstAider == true) { firstAiderPresent = true; } } List <StaffAttendanceVM> staffVM = new List <StaffAttendanceVM>(); EventVM @event = new EventVM(await _context.Events.Where(e => e.IsActive == true).FirstOrDefaultAsync(e => e.Id == eventId)); foreach (Staff s in staff) { staffVM.Add(new StaffAttendanceVM(s)); } var eventVM = new EventVM(await _context.Events.FindAsync(eventId)); BookNewStaffVM creator = new BookNewStaffVM(staffVM.OrderBy(s => s.Surname).ToList(), firstAiderPresent, eventVM.Id, eventVM.Title, numGuests); return(View(creator)); }
//Returns list of staff at event, based on staff id //Provides warning messages regarding needing more staff or first aider //Staff can be removed or re-added in bulk in this view via ajax public async Task <IActionResult> StaffAtEvent(int id) { var @event = await _context.Events.FirstOrDefaultAsync(m => m.Id == id); int numGuests = (await _context.Guests.Include(g => g.Event).Where(g => g.EventId == id).ToListAsync()).Count(); var staffing = await _context.Staffing.Include(g => g.Staff).Where(g => g.EventId == id).OrderBy(e => e.StaffId).ToListAsync(); var staff = await _context.Staff.Where(s => s.IsActive == true).Where(e => staffing.Any(b => b.StaffId.Equals(e.Id))).OrderBy(e => e.Id).ToListAsync(); List <StaffAttendanceVM> staffVM = new List <StaffAttendanceVM>(); bool firstAiderPresent = false; for (int i = 0; i < staffing.Count; i++) { staffVM.Add(new StaffAttendanceVM(staff[i], true)); if (firstAiderPresent == false && staffVM[i].FirstAider == true) { firstAiderPresent = true; } } BookNewStaffVM eventStaff = new BookNewStaffVM(staffVM.OrderBy(s => s.Surname).ToList(), firstAiderPresent, id, @event.Title, numGuests); return(View(eventStaff)); }