public async Task <IActionResult> Create([Bind("StaffId,EventId")] StaffBooking staffBooking) { if (ModelState.IsValid) { if (StaffBookingExists(staffBooking.StaffId, staffBooking.EventId)) { ModelState.AddModelError(String.Empty, "This staff member is already at the event."); return(View(staffBooking)); } _context.Add(staffBooking); await _context.SaveChangesAsync(); return(RedirectToAction("Index", new { id = staffBooking.EventId })); } var OnEvent = _context.StaffBooking.Include(c => c.Staff).Where(e => e.EventId == staffBooking.EventId).Select(c => new Staff() { Id = c.StaffId, Surname = c.Staff.Surname, FirstName = c.Staff.FirstName, FirstAider = c.Staff.FirstAider, Bookings = c.Staff.Bookings }).ToList(); var ToShow = _context.Staff.Where(x => !OnEvent.Contains(x)).ToList(); ViewData["StaffCheck"] = ToShow == null || ToShow.Count == 0; ViewData["StaffId"] = new SelectList(ToShow, "Id", "FirstName"); ViewData["EventId"] = staffBooking.EventId; return(View(staffBooking)); }
public async Task <IActionResult> Edit(int id, [Bind("StaffId,EventId")] StaffBooking staffBooking) { if (id != staffBooking.StaffId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(staffBooking); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!StaffBookingExists(staffBooking.StaffId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["EventId"] = new SelectList(_context.Events, "Id", "Title", staffBooking.EventId); ViewData["StaffId"] = new SelectList(_context.Staffs, "StaffId", "Email", staffBooking.StaffId); return(View(staffBooking)); }
public async Task <IActionResult> DeleteConfirmed(int id, [Bind("StaffId,EventId")] StaffBooking staffBooking) { await _context.StaffBooking .Include(s => s.StaffId) .Include(s => s.EventId) .FirstOrDefaultAsync(m => m.StaffId == id); _context.StaffBooking.Remove(staffBooking); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Create([Bind("StaffId,EventId")] StaffBooking staffBooking) { if (ModelState.IsValid) { _context.Add(staffBooking); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["EventId"] = new SelectList(_context.Events, "Id", "Title", staffBooking.EventId); ViewData["StaffId"] = new SelectList(_context.Staffs, "StaffId", "Email", staffBooking.StaffId); return(View(staffBooking)); }
public async Task <IActionResult> Create([Bind("StaffId,EventId")] StaffBooking staffBooking) { if (ModelState.IsValid) { if (!StaffBookingExists(staffBooking.StaffId, staffBooking.EventId)) { _context.Add(staffBooking); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } else { Debug.WriteLine("Guest Booking already Exists"); } } ViewData["EventId"] = new SelectList(_context.Events, "Id", "Title", staffBooking.EventId); ViewData["StaffId"] = new SelectList(_context.Staff, "Id", "Email", staffBooking.StaffId); return(View(staffBooking)); }
public async Task <IActionResult> Edit(int id, [Bind("StaffId,EventId")] StaffBooking staffBooking) { if (ModelState.IsValid) { if (!StaffBookingExists(staffBooking.StaffId, staffBooking.EventId)) { _context.Add(staffBooking); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } else { Debug.WriteLine("Guest Booking already Exists"); } } ViewData["StaffId"] = new SelectList(from s in _context.Staff select new { Id = s.Id, FullName = s.FirstName + " " + s.Surname }, "Id", "FullName", staffBooking.StaffId); ViewData["EventId"] = new SelectList(_context.Events, "Id", "Title", staffBooking.EventId); return(View(staffBooking)); }