Exemple #1
0
        public void PromotionMakeBooking(
            Guid servicePackagePromotionId,
            Guid userId
            )
        {
            Logging log =
                Logging.PerformanceTimeStart(
                    "Service",
                    "BusinessLogicLayer",
                    "ServiceService",
                    "PromotionMakeBooking",
                    userId
                    );

            using (var connection = new SqlConnection(Conn.ConnectionString)) {
                connection.Open();
                SqlTransaction transaction = connection.BeginTransaction();

                var promotionData = CrudeServicePackagePromotionData.GetByServicePackagePromotionId(servicePackagePromotionId);
                var packageData   = CrudeServicePackageData.GetByServicePackageId(promotionData.ServicePackageId);
                var clientData    = CrudeClientData.GetByClientId(promotionData.ClientId);
                var contactData   = CrudeClientContactMethodData.GetCurrentMail(promotionData.ClientId);

                // get flights
                // make booking
                var             bookingService = new BookingService();
                BookingContract booking        = bookingService.GetBookingEmpty(userId);

                // save booking
                // todo, transaction
                booking.Booking.BookingId =
                    bookingService.UpdateBooking(
                        booking.Booking.BookingId,
                        booking.Booking.BookingSourceRcd,
                        booking.BookingIdentifier.BookingIdentifierValue,
                        contactData.ContactMethodWay,
                        "PromotionMakeBooking",
                        string.Empty,
                        booking.Booking.FinancialCurrencyId,
                        booking.Booking.FinancialCostcentreId,
                        userId
                        );

                // flights
                if (packageData.DepartureAirportId != Guid.Empty)
                {
                    Guid flightId =
                        Flight.GetFlightMatching(
                            packageData.DepartureAirportId,
                            packageData.ArrivalAirportId
                            );

                    if (flightId != Guid.Empty)
                    {
                        bookingService.FlightAdd(
                            booking.Booking.BookingId,
                            flightId,
                            userId
                            );
                    }
                }

                // passengers
                bookingService.PassengerAdd(
                    booking.Booking.BookingId,
                    PassengerTypeRef.Adult,
                    clientData.FirstName + ' ' + clientData.MiddleName + ' ' + clientData.LastName,
                    userId
                    );

                // services (SSR)
                if (packageData.ServiceSpecialServiceRequestId != Guid.Empty)
                {
                    bookingService.BookingServiceSpecialServiceRequestAdd(
                        booking.Booking.BookingId,
                        packageData.ServiceSpecialServiceRequestId,
                        userId
                        );
                }

                // services (Hotel)
                if (packageData.ServiceHotelId != Guid.Empty)
                {
                    bookingService.BookingServiceHotelAdd(
                        booking.Booking.BookingId,
                        packageData.ServiceHotelId,
                        userId
                        );
                }

                // services (Car)
                if (packageData.ServiceCarRentalId != Guid.Empty)
                {
                    bookingService.BookingServiceCarRentalAdd(
                        booking.Booking.BookingId,
                        packageData.ServiceCarRentalId,
                        userId
                        );
                }

                // confirm booking
                bookingService.BookingConfirm(
                    booking.Booking.BookingId,
                    userId
                    );

                try {
                    transaction.Commit();
                    log.PerformanceTimeStop();
                } catch (Exception ex) {
                    transaction.Rollback();
                    log.Error(ex);
                    throw ex;
                }
            }
        }