public async Task <ActionResult> Cancel(Guid id, CancelBookingPostbackModel input) { var booking = await _context.Bookings .Include(b => b.AssignedPilot) .Include(b => b.BookingEvents) .FirstOrDefaultAsync(b => b.Id == id); var user = await _userManager.GetUserAsync(User); var userId = user.Id; if (!User.IsAdmin() && booking.AssignedPilot?.Id != userId) { return(RedirectToAction("Details", new { id = id, errorMessage = "Only admin or currently assigned pilot can cancel booking" })); } var cancelMessage = input.CancelMessage; if (string.IsNullOrWhiteSpace(cancelMessage)) { cancelMessage = "- no cancel message"; } booking.Canceled = true; booking.Completed = false; if (input.NotifyPassenger) { await _messageService.SendCancelMessage(cancelMessage, booking, user); _bookingService.AddEvent(booking, User, $"Canceled due to {cancelMessage} (notified passenger)"); } else { _bookingService.AddEvent(booking, User, $"Canceled due to {cancelMessage} (did not notify passenger)"); } _context.SaveChanges(); return(RedirectToAction("Details", new { Id = booking.Id })); }