public async Task <ActionResult> Complete(Guid id, CompleteBookingViewModel input) { var booking = await _context.Bookings .Include(b => b.AssignedPilot) .Include(b => b.BookingEvents) .FirstOrDefaultAsync(b => b.Id == id); var userId = _userManager.GetUserId(User); if (!User.IsAdmin() && booking.AssignedPilot.Id != userId) { return(RedirectToAction("Details", new { Id = booking.Id, errorMessage = "Only admin or currently assigned pilot can confirm booking" })); } //update passenger fee and completed status booking.PassengerFee = input.PassengerFee; booking.Canceled = false; booking.Completed = true; await _context.SaveChangesAsync(); _bookingService.AddEvent(booking, User, "booking confirmed"); _context.SaveChanges(); return(RedirectToAction("Details", new { Id = booking.Id })); }
public async Task <ActionResult> Complete(Guid id, CompleteBookingViewModel input) { var booking = await _context.Bookings .Include(b => b.AssignedPilot) .Include(b => b.BookingEvents) .FirstOrDefaultAsync(b => b.Id == id); var userId = _userManager.GetUserId(User); if (!User.IsAdmin() && booking.AssignedPilot.Id != userId) { return(RedirectToAction("Details", new { Id = booking.Id, errorMessage = "Only admin or currently assigned pilot can confirm booking" })); } //update passenger fee and completed status booking.PassengerFee = input.PassengerFee; booking.FlightType = input.FlightType; booking.PaymentType = input.PaymentType; //booking.IZettleAccount = !string.IsNullOrWhiteSpace(input.IZettleAccount) ? input.IZettleAccount : null; //booking.VippsAccount = !string.IsNullOrWhiteSpace(input.VippsAccount) ? input.VippsAccount : null; booking.BoatDriver = input.BoatDriver; var remainingFee = booking.PassengerFee; var boatDriverFee = booking.FlightType == FlightType.Winch ? Math.Min(remainingFee, _bookingCoordinatorSettings.DefaultBoatDriverFee) : 0m; remainingFee -= boatDriverFee; var clubFee = Math.Min(remainingFee, _bookingCoordinatorSettings.DefaultClubFee); remainingFee -= clubFee; booking.PilotFee = remainingFee; booking.BoatDriverFee = boatDriverFee; booking.Canceled = false; booking.Completed = true; booking.CompletedDate = DateTime.Now; await _context.SaveChangesAsync(); _bookingService.AddEvent(booking, User, "booking confirmed"); _context.SaveChanges(); return(RedirectToAction("Details", new { Id = booking.Id })); }