/// <summary>
        /// Checks for the availabity of a travel booking sent
        /// </summary>
        /// <param name="newTravelBooking"></param>
        /// <returns>Returns the status of availability. True if available</returns>
        private bool CheckAvailabilityForBooking(TravelBooking newTravelBooking)
        {
            bool isAvailable = false;

            Search.SearchManager manager = new Search.SearchManager();
            FlightBooking        booking = null;

            try
            {
                foreach (TravelDirection direction in newTravelBooking.GetBookingTravelDirections())
                {
                    booking = (FlightBooking)newTravelBooking.GetBookingForTravel(direction);

                    foreach (Schedule s in booking.TravelScheduleInfo.GetSchedules())
                    {
                        isAvailable = manager.GetAvailabilityForSchedule(s, booking.NoOfSeats, booking.DateOfJourney, booking.Class.ClassInfo);

                        if (!isAvailable)
                        {
                            break;
                        }
                    }
                }
            }
            catch (Search.FlightSeatsAvailabilityException)
            {
                throw;
            }

            return(isAvailable);
        }
        /// <summary>
        /// Process Air Travel Booking payment
        /// </summary>
        /// <param name="newTravelBooking"></param>
        /// <param name="cardForBooking"></param>
        /// <param name="status"></param>
        /// <returns>Returns payment reference number</returns>
        private string ProcessAirTravelBookingPayment(TravelBooking newTravelBooking, Card cardForBooking, out PaymentStatus status)
        {
            string  paymentReferenceNumber = string.Empty;
            decimal travelTotalCost        = 0;

            //Calculating the cost
            travelTotalCost = newTravelBooking.GetBookingForTravel(TravelDirection.OneWay).TotalCost;

            if (newTravelBooking.IsReturnAvailable())
            {
                travelTotalCost += newTravelBooking.GetBookingForTravel(TravelDirection.Return).TotalCost;
            }


            //Make a Payment and update the booking reference number into booking object
            try
            {
                bool isCardValid = ValidateCardInfo(cardForBooking);

                if (isCardValid)
                {
                    paymentReferenceNumber = MakePayment(cardForBooking, travelTotalCost, out status);

                    if (PaymentStatus.Success == status)
                    {
                        foreach (TravelDirection direction in newTravelBooking.GetBookingTravelDirections())
                        {
                            //Calling the Parameterized Constructor
                            //This is done once the class variables are set to private set
                            //and a paramterized constructor is introduced
                            //Using VS - Effectively - CR - STYCBG09.04
                            Payment newPayment = new Payment(DateTime.Now, travelTotalCost, paymentReferenceNumber);

                            newTravelBooking.GetBookingForTravel(direction).PaymentInfo = newPayment;
                        }
                    }
                    else
                    {
                        throw new PaymentProcessException("Unable to Process Payment");
                    }
                }
                else
                {
                    throw new PaymentProcessException("Unable to Process Payment");
                }
            }
            catch (PaymentProcessException ex)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new PaymentProcessException("Unable to Process Payment", ex);
            }

            return(paymentReferenceNumber);
        }
        /// <summary>
        /// Process Air Travel Booking payment
        /// </summary>
        /// <param name="newTravelBooking"></param>
        /// <param name="cardForBooking"></param>
        /// <param name="status"></param>
        /// <returns>Returns payment reference number</returns>
        private string ProcessAirTravelBookingPayment(TravelBooking newTravelBooking, Card cardForBooking, out PaymentStatus status)
        {
            string  paymentReferenceNumber = string.Empty;
            decimal travelTotalCost        = 0;

            //Calculating the cost
            travelTotalCost = newTravelBooking.GetBookingForTravel(TravelDirection.OneWay).TotalCost;

            if (newTravelBooking.IsReturnAvailable())
            {
                travelTotalCost = newTravelBooking.GetBookingForTravel(TravelDirection.Return).TotalCost;
            }


            //Make a Payment and update the booking reference number into booking object
            try
            {
                bool isCardValid = ValidateCardInfo(cardForBooking);

                if (isCardValid)
                {
                    paymentReferenceNumber = MakePayment(cardForBooking, travelTotalCost, out status);

                    if (PaymentStatus.Success == status)
                    {
                        foreach (TravelDirection direction in newTravelBooking.GetBookingTravelDirections())
                        {
                            Payment newPayment = new Payment();
                            newPayment.Amount      = travelTotalCost;
                            newPayment.PaymentDate = DateTime.Now;
                            newPayment.ReferenceNo = paymentReferenceNumber;

                            newTravelBooking.GetBookingForTravel(direction).PaymentInfo = newPayment;
                        }
                    }
                    else
                    {
                        throw new PaymentProcessException("Unable to Process Payment");
                    }
                }
                else
                {
                    throw new PaymentProcessException("Unable to Process Payment");
                }
            }
            catch (PaymentProcessException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new PaymentProcessException("Unable to Process Payment", ex);
            }

            return(paymentReferenceNumber);
        }
        /// <summary>
        /// Processes a booking to be made - flight
        /// </summary>
        /// <param name="newTravelBooking"></param>
        /// <param name="cardForBooking"></param>
        /// <returns>Returns a travel booking object updated with all the booking information</returns>
        public TravelBooking ProcessAirTravelBooking(TravelBooking newTravelBooking, Card cardForBooking)
        {
            bool   isAvailable        = false;
            string bookingReferenceNo = string.Empty;

            PaymentStatus status;
            string        paymentReferenceNumber = string.Empty;

            //Checking for Availability of Schedules before porcessing the booking
            //1. Check for Availablity
            try
            {
                isAvailable = CheckAvailabilityForBooking(newTravelBooking);
            }
            catch (Search.FlightSeatsAvailabilityException Ex)
            {
                throw Ex;
            }
            catch (Exception ex)
            {
                throw new Search.FlightSeatsAvailabilityException("Seats Not Available", ex);
            }

            //If available, then make payment and store in database using transactions
            //If Available then do rest of the code
            if (isAvailable)
            {
                TransactionOptions options = new TransactionOptions();
                options.IsolationLevel = IsolationLevel.ReadCommitted;
                options.Timeout        = TransactionManager.MaximumTimeout;

                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, options))
                {
                    try
                    {
                        //Processing the payment
                        paymentReferenceNumber = ProcessAirTravelBookingPayment(newTravelBooking, cardForBooking, out status);

                        //Store in database
                        if (PaymentStatus.Success == status)
                        {
                            //Persist in the database
                            foreach (TravelDirection Direction in newTravelBooking.GetBookingTravelDirections())
                            {
                                bookingReferenceNo = StoreBookingInDatabase(newTravelBooking.GetBookingForTravel(Direction));
                                newTravelBooking.GetBookingForTravel(Direction).ReferenceNo = bookingReferenceNo;
                            }

                            scope.Complete();
                        }
                    }
                    catch (PaymentProcessException ex)
                    {
                        scope.Dispose();
                        throw ex;
                    }
                    catch (InvalidBookingTypeException ex)
                    {
                        scope.Dispose();
                        throw ex;
                    }
                    catch (StoreBookingInDatabaseException ex)
                    {
                        scope.Dispose();
                        throw new BookingException("Unable to Book Tickets", ex);
                    }
                    catch (Exception ex)
                    {
                        scope.Dispose();
                        throw new BookingException("Unable to Book Tickets", ex);
                    }
                }
            }

            return(newTravelBooking);
        }
Exemple #5
0
        /// <summary>
        /// Process Air Travel Booking payment
        /// </summary>
        /// <param name="newTravelBooking"></param>
        /// <param name="cardForBooking"></param>
        /// <param name="status"></param>
        /// <returns>Returns payment reference number</returns>
        private string ProcessAirTravelBookingPayment(TravelBooking newTravelBooking, Card cardForBooking, out PaymentStatus status)
        {
            string  paymentReferenceNumber = string.Empty;
            decimal travelTotalCost        = 0;

            //Calculating the cost
            travelTotalCost = newTravelBooking.GetBookingForTravel(TravelDirection.OneWay).TotalCost;

            if (newTravelBooking.IsReturnAvailable())
            {
                travelTotalCost += newTravelBooking.GetBookingForTravel(TravelDirection.Return).TotalCost;
            }

            FlightBooking bookingOnward = (FlightBooking)(newTravelBooking.GetBookingForTravel(TravelDirection.OneWay));

            if (bookingOnward.Insurance != null)
            {
                decimal travelInsuranceOnward = (bookingOnward.Insurance.Amount);
                travelTotalCost += travelInsuranceOnward;
                newTravelBooking.GetBookingForTravel(TravelDirection.OneWay).TotalCost += travelInsuranceOnward;
            }

            FlightBooking bookingReturn = (FlightBooking)(newTravelBooking.GetBookingForTravel(TravelDirection.Return));

            if (bookingReturn != null && bookingReturn.Insurance != null)
            {
                decimal travelInsuranceReturn = (bookingReturn.Insurance.Amount);
                travelTotalCost += travelInsuranceReturn;
                newTravelBooking.GetBookingForTravel(TravelDirection.Return).TotalCost += travelInsuranceReturn;
            }
            //Make a Payment and update the booking reference number into booking object
            try
            {
                paymentReferenceNumber = MakePayment(cardForBooking, travelTotalCost, out status);

                if (status == PaymentStatus.Success)
                {
                    foreach (TravelDirection direction in newTravelBooking.GetBookingTravelDirections())
                    {
                        Payment newPayment = new Payment();
                        newPayment.Amount      = travelTotalCost;
                        newPayment.PaymentDate = DateTime.Now;
                        newPayment.ReferenceNo = paymentReferenceNumber;

                        newTravelBooking.GetBookingForTravel(direction).PaymentInfo = newPayment;
                    }
                }
                else
                {
                    throw new PaymentProcessException("Unable to Process Payment");
                }
            }
            catch (PaymentProcessException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new PaymentProcessException("Unable to Process Payment", ex);
            }

            return(paymentReferenceNumber);
        }