public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Location,Date")] StaffBookings 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))); } return(View(staffBooking)); }
public async Task <IActionResult> Edit(int id, [Bind("id,StaffId,EventId,Date")] StaffBookings staffBookings) { //Checks if the booking exists. if (id != staffBookings.id) { return(NotFound()); } if (ModelState.IsValid) { try { //Finds the staff booking and updates it. StaffBookings s = await _context.StaffBookings.FindAsync(id); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!StaffBookingsExists(staffBookings.id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } //Adds the event title to the view bag to be displayed in the view, I used viewbag as it is easier to populat e adrop down box using this method. ViewData["EventId"] = new SelectList(_context.Events, "Id", "Title", staffBookings.EventId); return(View(staffBookings)); }
public async Task <IActionResult> Create([Bind("StaffId,EventId,Attended")] StaffBookings staffBooking) { if (ModelState.IsValid) { _context.Add(staffBooking); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(staffBooking)); }
public async Task <IActionResult> Create([Bind("id,StaffId,EventId,Date")] StaffBookings staffBookings) { //If the booking exists then it adds the booking that is created based off the data inputted in the view. if (ModelState.IsValid) { _context.Add(staffBookings); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } //Adds the eventID and event title to the view bag to be displayed in the view, I used viewbag as it is easier to populat e adrop down box using this method. ViewData["EventId"] = new SelectList(_context.Events, "Id", "Title", staffBookings.EventId); return(View(staffBookings)); }