Esempio n. 1
0
        public async Task <BookingResponseModel> CreateMultiDayBookingAsync(BookingModelMultiDay multiDayBooking)
        {
            var response = new BookingResponseModel {
                IsSuccess = true
            };

            using var transaction = await _context.Database.BeginTransactionAsync(System.Data.IsolationLevel.RepeatableRead);

            try
            {
                var completeByDate = await _workingDayService.GetCompleteByDateAsync(multiDayBooking.VisitStartDate);

                var bookingId = (await _context.Set <Booking>().OrderByDescending(b => b.Id).FirstOrDefaultAsync())?.Id ?? 0 + 1;

                response.BookingReference = IdGenerator.GenerateBookingReference(bookingId);
                response.CreatedDate      = DateTime.UtcNow;

                var booking = new Booking()
                {
                    CreatedDate          = response.CreatedDate,
                    CompleteByDate       = completeByDate,
                    BookingReference     = response.BookingReference,
                    BookingTypeId        = (int)BookingTypes.StandardOrderVisit,
                    ReaderTicket         = multiDayBooking.ReaderTicket,
                    FirstName            = multiDayBooking.FirstName,
                    LastName             = multiDayBooking.LastName,
                    Email                = multiDayBooking.Email,
                    IsAcceptTsAndCs      = true,
                    IsAcceptCovidCharter = true,
                    IsNoFaceCovering     = false,
                    IsNoShow             = false,
                    SeatId               = multiDayBooking.SeatId,
                    BookingStatusId      = (int)BookingStatuses.Submitted,
                    VisitStartDate       = multiDayBooking.VisitStartDate,
                    VisitEndDate         = multiDayBooking.VisitEndDate,
                    LastModifiedBy       = Modified_By
                };

                var bookingModel = new BookingModel()
                {
                    BookingReference     = booking.BookingReference,
                    BookingType          = BookingTypes.StandardOrderVisit,
                    ReaderTicket         = booking.ReaderTicket,
                    VisitStartDate       = booking.VisitStartDate,
                    VisitEndDate         = booking.VisitEndDate,
                    CreatedDate          = booking.CreatedDate,
                    CompleteByDate       = booking.CompleteByDate,
                    FirstName            = booking.FirstName,
                    LastName             = booking.LastName,
                    Email                = booking.Email,
                    IsAcceptTsAndCs      = true,
                    IsAcceptCovidCharter = true,
                    IsNoFaceCovering     = false,
                    IsNoShow             = false,
                    SeatId               = booking.SeatId,
                    BookingStatus        = BookingStatuses.Submitted,
                    OrderDocuments       = new List <OrderDocumentModel>(),
                    LastModifiedBy       = Modified_By
                };

                await _context.Set <Booking>().AddAsync(booking);

                // Check that the seat booked in the back office application is still available.
                List <SeatModel> availableSeats = await _availabilityService.GetAvailabileSeatsForMultiDayVisitAsync(booking.VisitStartDate, booking.VisitEndDate, true);

                SeatModel selectedSeat = availableSeats.SingleOrDefault(s => s.Id == booking.SeatId);
                if (selectedSeat == null)
                {
                    throw new Exception($"Error creating booking for user {booking.FirstName} {booking.LastName}, email {booking.Email} fromm the Back Office.  The requested seat id {booking.SeatId} is no longer available for the date range {booking.VisitStartDate} to {booking.VisitEndDate}.");
                }

                await _context.SaveChangesAsync();

                await transaction.CommitAsync();

                await _emailService.SendEmailAsync(EmailType.BookingConfirmation, multiDayBooking.Email, bookingModel);
            }
            catch (Exception)
            {
                await transaction?.RollbackAsync();

                response.IsSuccess    = false;
                response.ErrorMessage = "Error creating multi day booking";
            }

            return(response);
        }
Esempio n. 2
0
        public async Task <ActionResult <BookingResponseModel> > CreateMultiDayBooking(BookingModelMultiDay bookingModelMultiDay)
        {
            var result = await _bookingService.CreateMultiDayBookingAsync(bookingModelMultiDay);

            return(Ok(result));
        }