示例#1
0
        public void Departure_date_can_be_rescheduled_whilst_pending_confirmation_from_airline()
        {
            var id = Guid.NewGuid();
            var customerId = Guid.NewGuid();
            var initialDeparture = new DateTime(2015, 04, 22);
            var booking = new FlightBooking(id, initialDeparture, customerId);

            var rescheduledDeparture = new DateTime(2015, 04, 23);
            booking.Reschedule(rescheduledDeparture);

            Assert.AreEqual(rescheduledDeparture, booking.DepartureDate);
        }
示例#2
0
        public void Departure_date_cannot_be_rescheduled_after_booking_confirmed_by_airline()
        {
            var id = Guid.NewGuid();
            var customerId = Guid.NewGuid();
            var initialDeparture = new DateTime(2015, 04, 22);
            var booking = new FlightBooking(id, initialDeparture, customerId);

            booking.Confirm();

            var rescheduledDeparture = new DateTime(2015, 04, 23);

            try
            {
                booking.Reschedule(rescheduledDeparture);
            }
            catch (RescheduleRejected rr)
            {
                // Exception was thrown so test should pass
                return;
            }

            Assert.Fail("Reschedule was not rejected");
        }
示例#3
0
文件: MainDialog.cs 项目: rvba/bot2
        // Shows a warning if the requested From or To cities are recognized as entities but they are not in the Airport entity list.
        // In some cases LUIS will recognize the From and To composite entities as a valid cities but the From and To Airport values
        // will be empty if those entity values can't be mapped to a canonical item in the Airport.
        private static async Task ShowWarningForUnsupportedCities(ITurnContext context, FlightBooking luisResult, CancellationToken cancellationToken)
        {
            var unsupportedCities = new List <string>();

            var fromEntities = luisResult.FromEntities;

            if (!string.IsNullOrEmpty(fromEntities.From) && string.IsNullOrEmpty(fromEntities.Airport))
            {
                unsupportedCities.Add(fromEntities.From);
            }

            var toEntities = luisResult.ToEntities;

            if (!string.IsNullOrEmpty(toEntities.To) && string.IsNullOrEmpty(toEntities.Airport))
            {
                unsupportedCities.Add(toEntities.To);
            }

            if (unsupportedCities.Any())
            {
                var messageText = $"Sorry but the following airports are not supported: {string.Join(',', unsupportedCities)}";
                var message     = MessageFactory.Text(messageText, messageText, InputHints.IgnoringInput);
                await context.SendActivityAsync(message, cancellationToken);
            }
        }
示例#4
0
        public IActionResult Book([FromBody] Booking bookingRequest)
        {
            if (!(bookingRequest.PassengerCount > 0))
            {
                return(BadRequest("At least 1 passenger is required."));
            }

            Flight flight = flightRepository.Find(bookingRequest.FlightId);

            if (flight == null || flight.PassengerCapacity <= 0)
            {
                return(BadRequest("Invalid Flight."));
            }

            Passenger passenger = passengerRepository.Find(bookingRequest.PassengerId);

            if (passenger == null || string.IsNullOrWhiteSpace(passenger.IdentityNumber))
            {
                return(BadRequest("Invalid Passenger."));
            }

            if (bookingRequest.PassengerCount > flight.PassengerCapacity)
            {
                return(BadRequest("Passenger Capacity exceeded."));
            }

            Booking booking = bookingRepository.Find(bookingRequest.TravelDate, bookingRequest.FlightId, bookingRequest.PassengerId);

            if (booking != null && booking.PassengerCount > 0)
            {
                return(BadRequest("Flight already booked for the same travel day by the same passenger."));
            }
            else
            {
                // Valid booking request, so proceed.
                bookingRepository.Add(bookingRequest);
            }

            FlightBooking flightBooking = flightBookingRepository.Find(bookingRequest.FlightId, bookingRequest.TravelDate);

            if (flightBooking != null && flightBooking.FlightBookingId > 0)
            {
                var currentPassengerCount = flightBooking.PassengerCount;

                if ((currentPassengerCount + bookingRequest.PassengerCount) > flight.PassengerCapacity)
                {
                    return(BadRequest("Passenger Capacity exceeded."));
                }
                else
                {
                    // Valid passenger count.
                    flightBooking.PassengerCount = (short)(currentPassengerCount + bookingRequest.PassengerCount);
                    flightBookingRepository.Update(flightBooking);
                }
            }

            if (flightBooking == null || flightBooking.FlightBookingId <= 0)
            {
                flightBooking = new FlightBooking
                {
                    TravelDate     = bookingRequest.TravelDate,
                    FlightId       = bookingRequest.FlightId,
                    PassengerCount = bookingRequest.PassengerCount
                };

                // Valid booking request, so proceed.
                flightBookingRepository.Add(flightBooking);
            }

            return(Ok("Flight Booked."));
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            #region Obtain the bookingObjects From Session
            if (!IsPostBack)
            {
                decimal       TotalCost           = 0;
                TravelBooking _travelBooking      = null;
                FlightBooking flightbookingonward = null;
                FlightBooking flightbookingreturn = null;
                if (Session["travelBooking"] != null)
                {
                    _travelBooking      = (TravelBooking)Session["travelbooking"];
                    flightbookingonward = (FlightBooking)_travelBooking.GetBookingForTravel(TravelDirection.OneWay);
                    flightbookingreturn = (FlightBooking)_travelBooking.GetBookingForTravel(TravelDirection.Return);
                }
                else
                {
                    Response.Redirect("~/Index.aspx");
                }
                if (flightbookingonward != null)
                {
                    FlightBooking flightbooking = flightbookingonward;
                    int           NoOfSeats     = flightbooking.NoOfSeats;
                    lblHeaderDepart.Text = flightbooking.DateOfJourney.ToString("ddd, dd MMM, yyyy");
                    lblAdults.Text       = NoOfSeats.ToString();

                    List <Passenger> lstPassenger = flightbooking.GetPassengers();;

                    rptrPassengerInfo.DataSource = lstPassenger;
                    rptrPassengerInfo.DataBind();

                    rptrOnwardFlightInfo.DataSource = flightbooking.TravelScheduleInfo.GetSchedules();
                    rptrOnwardFlightInfo.DataBind();

                    TotalCost = flightbooking.TotalCost;

                    lblHeaderDateSeparator.Visible = false;


                    //Fill Contacts details
                    lblName.Text         = flightbooking.Contact.ContactName;
                    lblAddressline1.Text = flightbooking.Contact.MobileNo;
                    lblState.Text        = flightbooking.Contact.State;
                    lblCity.Text         = flightbooking.Contact.City;
                    lblEmail.Text        = flightbooking.Contact.Email;
                    lblMobno.Text        = flightbooking.Contact.MobileNo;
                    lblPhno.Text         = flightbooking.Contact.PhoneNo;

                    lblHeaderFromCity.Text = flightbooking.TravelScheduleInfo.GetSchedules()[0].RouteInfo.FromCity.Name;
                    lblHeaderToCity.Text   = flightbooking.TravelScheduleInfo.GetSchedules()[0].RouteInfo.ToCity.Name;

                    lblOnwardTicketNo.Text = flightbooking.ReferenceNo;
                }

                if (flightbookingreturn != null)
                {
                    FlightBooking flightbooking = flightbookingreturn;
                    int           NoOfSeats     = flightbooking.NoOfSeats;
                    lblHeaderReturn.Text = flightbooking.DateOfJourney.ToString("ddd, dd MMM, yyyy");

                    rptrReturnFlightInfo.DataSource = flightbooking.TravelScheduleInfo.GetSchedules();
                    rptrReturnFlightInfo.DataBind();

                    divReturn.Visible = true;

                    TotalCost = TotalCost + flightbooking.TotalCost;

                    lblHeaderDateSeparator.Visible = true;

                    pnlReturnTicketNo.Visible = true;
                    lblReturnTicketNo.Text    = flightbooking.ReferenceNo;
                }

                //Insurance Display
                decimal insuranceOnwardAmount = 0;
                decimal insuranceReturnAmount = 0;
                if (flightbookingonward.Insurance != null)
                {
                    insuranceOnwardAmount = flightbookingonward.Insurance.Amount;

                    if (flightbookingreturn != null && flightbookingreturn.Insurance != null)
                    {
                        insuranceReturnAmount = flightbookingreturn.Insurance.Amount;
                    }

                    lblInsuranceText.Text  = "You have opted to go for travel insurance for the amount : ";
                    lblInsuranceValue.Text = "Onward Journey : INR " + (insuranceOnwardAmount / flightbookingonward.NoOfSeats) + " /- Per Passenger ";

                    if (insuranceReturnAmount > 0)
                    {
                        lblInsuranceValue.Text += "-- Return Journey : INR " + (insuranceReturnAmount / flightbookingreturn.NoOfSeats) + " /- Per Passenger ";
                    }

                    lblInsuranceText.Visible  = true;
                    lblInsuranceValue.Visible = true;
                }
                else
                {
                    lblInsuranceValue.Text    = "INR 0.0";
                    lblInsuranceValue.Visible = true;
                }

                lblTotalPrice.Text = "INR " + (TotalCost - (insuranceOnwardAmount + insuranceReturnAmount)).ToString();

                lblGrandTotal.Text = "INR " + TotalCost.ToString();


                if (Session["happymiles"] != null)
                {
                    int happyMiles = (int)Session["happymiles"];
                    lblHappyMiles.Text = "Happy miles earned in this transaction is " + happyMiles.ToString();
                }
            }
            //Clean up the session
            Session.Clear();

            #endregion
        }
示例#6
0
        protected void btnBook_Click(object sender, EventArgs e)
        {
            int adults = Convert.ToInt32(Request.QueryString["adults"].ToString());

            int             td = Convert.ToInt16(Request.QueryString["td"].ToString());
            TravelDirection traveldirection = (TravelDirection)td;

            List <string> onwardids = new List <string>();

            for (int i = 0; i < hdnScheduleOnwardSelectedId.Value.Split('|').Length; i++)
            {
                onwardids.Add(hdnScheduleOnwardSelectedId.Value.Split('|')[i].ToString());
            }

            List <TravelSchedule> lstTravelSchedule = (List <TravelSchedule>)Session["flightbookingonwardresults"];
            List <Schedule>       resultonward      = (from t in lstTravelSchedule.SelectMany(schedule => schedule.GetSchedules())
                                                       where onwardids.Contains(t.ID.ToString())
                                                       select t).ToList();

            TravelSchedule objOnwardSchedule   = new TravelSchedule();
            decimal        OnwardCostPerTicket = 0;
            decimal        OnwardTotalCost     = 0;

            foreach (Schedule schedule in resultonward)
            {
                objOnwardSchedule.AddSchedule(schedule);
                OnwardCostPerTicket = OnwardCostPerTicket + schedule.GetFlightCosts().FirstOrDefault().CostPerTicket;
            }


            OnwardTotalCost = OnwardCostPerTicket * adults;

            FlightBooking flightbookingonward = new FlightBooking();

            flightbookingonward.NoOfSeats   = adults;
            flightbookingonward.BookingType = BookingTypes.Flight;
            FlightClass Class = new FlightClass();

            Class.ClassInfo           = (TravelClass)Enum.Parse(typeof(TravelClass), Request.QueryString["class"]);
            flightbookingonward.Class = Class;
            flightbookingonward.TravelScheduleInfo = objOnwardSchedule;
            flightbookingonward.DateOfJourney      = Convert.ToDateTime(Request.QueryString["depart_date"]);
            flightbookingonward.TotalCost          = OnwardTotalCost;

            if (Membership.GetUser() != null)
            {
                flightbookingonward.UserName = Membership.GetUser().UserName;
            }
            else
            {
                flightbookingonward.UserName = "******";
            }


            TravelBooking travelbooking = new TravelBooking();

            travelbooking.AddBookingForTravel(TravelDirection.OneWay, flightbookingonward);

            if (traveldirection == TravelDirection.Return)
            {
                List <string> retunrids = new List <string>();
                for (int i = 0; i < hdnScheduleReturnSelectedId.Value.Split('|').Length; i++)
                {
                    retunrids.Add(hdnScheduleReturnSelectedId.Value.Split('|')[i].ToString());
                }

                List <TravelSchedule> lstTravelScheduleReturn = (List <TravelSchedule>)Session["flightbookingreturnresults"];
                List <Schedule>       resultreturn            = (from t in lstTravelScheduleReturn.SelectMany(schedule => schedule.GetSchedules())
                                                                 where retunrids.Contains(t.ID.ToString())
                                                                 select t).ToList();

                TravelSchedule objReturnSchedule   = new TravelSchedule();
                decimal        ReturnTotalCost     = 0;
                decimal        ReturnCostPerTicket = 0;
                foreach (Schedule schedule in resultreturn)
                {
                    objReturnSchedule.AddSchedule(schedule);
                    ReturnCostPerTicket = ReturnCostPerTicket + schedule.GetFlightCosts().FirstOrDefault().CostPerTicket;
                }
                ReturnTotalCost = ReturnCostPerTicket * adults;

                FlightBooking flightbookingreturn = new FlightBooking();
                flightbookingreturn.NoOfSeats          = adults;
                flightbookingreturn.TravelScheduleInfo = objReturnSchedule;
                flightbookingreturn.DateOfJourney      = Convert.ToDateTime(Request.QueryString["return_date"]);
                flightbookingreturn.TotalCost          = ReturnTotalCost;

                if (Membership.GetUser() != null)
                {
                    flightbookingreturn.UserName = Membership.GetUser().UserName;
                }
                else
                {
                    flightbookingreturn.UserName = "******";
                }


                travelbooking.AddBookingForTravel(TravelDirection.Return, flightbookingreturn);
            }

            Session["travelbooking"] = travelbooking;

            Response.Redirect("~/booking/passengers.aspx");
        }
示例#7
0
        ///// <summary>
        ///// Inserts into database the booking for air travel
        ///// </summary>
        ///// <param name="newBooking"></param>
        ///// <param name="dbConnection"></param>
        ///// <exception cref="AirTravelBookingException">Throws the AirTravelBookingException, if unable to store a booking</exception>
        ///// <returns>Returns the booking reference number</returns>
        //public string MakeBooking(Booking newBooking, Database dbConnection)
        //{
        //    string bookingReferenceNo = string.Empty;

        //    //Downcast to flight booking
        //    FlightBooking airBooking = (FlightBooking)newBooking;

        //    try
        //    {
        //        //Write code to store data into database
        //        DbCommand command = dbConnection.GetStoredProcCommand("BookFlightTicket");
        //        dbConnection.AddInParameter(command, "@TypeID", DbType.Int32, (int)airBooking.BookingType);
        //        dbConnection.AddInParameter(command, "@DateOfJourney", DbType.DateTime, airBooking.DateOfJourney);
        //        dbConnection.AddInParameter(command, "@NoOfSeats", DbType.Int32, airBooking.NoOfSeats);
        //        dbConnection.AddInParameter(command, "@ClassID", DbType.Int32, (int)airBooking.Class.ClassInfo);
        //        dbConnection.AddInParameter(command, "@ContactName", DbType.String, airBooking.Contact.ContactName);
        //        dbConnection.AddInParameter(command, "@Address", DbType.String, airBooking.Contact.Address);
        //        dbConnection.AddInParameter(command, "@City", DbType.String, airBooking.Contact.City);
        //        dbConnection.AddInParameter(command, "@State", DbType.String, airBooking.Contact.State);
        //        dbConnection.AddInParameter(command, "@PinCode", DbType.String, airBooking.Contact.PinCode);
        //        dbConnection.AddInParameter(command, "@Email", DbType.String, airBooking.Contact.Email);
        //        dbConnection.AddInParameter(command, "@PhoneNo", DbType.String, airBooking.Contact.PhoneNo);
        //        dbConnection.AddInParameter(command, "@MobileNo", DbType.String, airBooking.Contact.MobileNo);
        //        dbConnection.AddInParameter(command, "@PaymentRefernceNo", DbType.String, airBooking.PaymentInfo.ReferenceNo);
        //        dbConnection.AddInParameter(command, "@TotalCost", DbType.Decimal, airBooking.TotalCost);

        //        //Concatenate to send to database as a single string
        //        string passengerDetails = String.Empty;
        //        string name = String.Empty;
        //        string gender = String.Empty;
        //        string dob = String.Empty;

        //        foreach (Passenger p in airBooking.GetPassengers())
        //        {
        //            name = p.Name;
        //            gender = p.Gender.ToString();
        //            dob = p.DateOfBirth.ToShortDateString();

        //            passengerDetails = name + "|" + gender + "|" + dob + ";";
        //        }

        //        dbConnection.AddInParameter(command, "@PassengerDetails", DbType.String, passengerDetails);
        //        dbConnection.AddOutParameter(command, "@BookingReferenceNumber", DbType.String, 100);
        //        dbConnection.AddOutParameter(command, "@LastBookingID", DbType.Int64, 0);

        //        //Execute the command
        //        dbConnection.ExecuteNonQuery(command);

        //        //Get the values from the database
        //        bookingReferenceNo = dbConnection.GetParameterValue(command, "@BookingReferenceNumber").ToString();
        //        long bookingId = Convert.ToInt64(dbConnection.GetParameterValue(command, "@LastBookingID"));

        //        //Insert the schedules for a booking
        //        foreach (Schedule s in airBooking.TravelScheduleInfo.GetSchedules())
        //        {
        //            try
        //            {
        //                InsertBookingSchedule(bookingId, s.ID, s.GetFlightCosts().FirstOrDefault().CostPerTicket, dbConnection);
        //            }
        //            catch (AirTravelBookingException)
        //            {
        //                throw;
        //            }
        //        }
        //    }
        //    catch(AirTravelBookingException)
        //    {
        //        throw;
        //    }
        //    catch (DbException ex)
        //    {
        //        throw new AirTravelBookingException("Unable to insert air travel booking", ex);
        //    }
        //    catch (Exception ex)
        //    {
        //        throw new AirTravelBookingException("Unable to insert air travel booking", ex);
        //    }

        //    return bookingReferenceNo;
        //}

        ///// <summary>
        ///// Inserts the schedule for a booking
        ///// </summary>
        ///// <param name="bookingId"></param>
        ///// <param name="scheduleId"></param>
        ///// <param name="costPerTicket"></param>
        ///// <param name="dbConnection"></param>
        ///// <returns></returns>
        //private bool InsertBookingSchedule(long bookingId, long scheduleId, decimal costPerTicket, Database dbConnection)
        //{
        //    bool isStored = false;

        //    try
        //    {
        //        //Write code to store data into database
        //        DbCommand command = dbConnection.GetStoredProcCommand("InsertFlightTicketSchedule");
        //        dbConnection.AddInParameter(command, "@BookingId", DbType.Int64, bookingId);
        //        dbConnection.AddInParameter(command, "@ScheduleId", DbType.Int64, scheduleId);
        //        dbConnection.AddInParameter(command, "@CostPerTicket", DbType.Decimal, costPerTicket);

        //        //Execute the command
        //        dbConnection.ExecuteNonQuery(command);

        //        isStored = true;
        //    }
        //    catch (DbException ex)
        //    {
        //        throw new AirTravelBookingException("Unable to insert air travel schedule", ex);
        //    }
        //    catch (Exception ex)
        //    {
        //        throw new AirTravelBookingException("Unable to insert air travel schedule", ex);
        //    }

        //    return isStored;
        //}
        #endregion

        #region Method to store booking details for an air travel

        /// <summary>
        /// Inserts into database the booking for air travel
        /// </summary>
        /// <param name="newBooking"></param>
        /// <param name="dbConnection"></param>
        /// <exception cref="AirTravelBookingException">Throws the AirTravelBookingException, if unable to store a booking</exception>
        /// <returns>Returns the booking reference number</returns>
        public string MakeBooking(Booking newBooking, IDbConnection dbConnection)
        {
            string bookingReferenceNo = string.Empty;

            //Downcast to flight booking
            FlightBooking airBooking = (FlightBooking)newBooking;

            try
            {
                dbConnection.Open();

                IDbCommand cmd = dbConnection.CreateCommand();
                cmd.CommandText = "BookFlightTicket";
                cmd.CommandType = CommandType.StoredProcedure;

                IDbDataParameter p1 = cmd.CreateParameter();
                p1.ParameterName = "@TypeID";
                p1.Value         = (int)airBooking.BookingType;
                cmd.Parameters.Add(p1);

                IDbDataParameter p2 = cmd.CreateParameter();
                p2.ParameterName = "@DateOfJourney";
                p2.Value         = airBooking.DateOfJourney;
                cmd.Parameters.Add(p2);

                IDbDataParameter p3 = cmd.CreateParameter();
                p3.ParameterName = "@NoOfSeats";
                p3.Value         = airBooking.NoOfSeats;
                cmd.Parameters.Add(p3);

                IDbDataParameter p4 = cmd.CreateParameter();
                p4.ParameterName = "@ClassID";
                p4.Value         = (int)airBooking.Class.ClassInfo;
                cmd.Parameters.Add(p4);


                IDbDataParameter p5 = cmd.CreateParameter();
                p5.ParameterName = "@ContactName";
                p5.Value         = airBooking.Contact.ContactName;
                cmd.Parameters.Add(p5);

                IDbDataParameter p6 = cmd.CreateParameter();
                p6.ParameterName = "@Address";
                p6.Value         = airBooking.Contact.Address;
                cmd.Parameters.Add(p6);

                IDbDataParameter p7 = cmd.CreateParameter();
                p7.ParameterName = "@City";
                p7.Value         = airBooking.Contact.City;
                cmd.Parameters.Add(p7);

                IDbDataParameter p8 = cmd.CreateParameter();
                p8.ParameterName = "@State";
                p8.Value         = airBooking.Contact.State;
                cmd.Parameters.Add(p8);


                IDbDataParameter p9 = cmd.CreateParameter();
                p9.ParameterName = "@PinCode";
                p9.Value         = "000000";
                cmd.Parameters.Add(p9);


                IDbDataParameter p10 = cmd.CreateParameter();
                p10.ParameterName = "@Email";
                p10.Value         = airBooking.Contact.Email;
                cmd.Parameters.Add(p10);


                IDbDataParameter p11 = cmd.CreateParameter();
                p11.ParameterName = "@PhoneNo";
                p11.Value         = airBooking.Contact.PhoneNo;
                cmd.Parameters.Add(p11);

                IDbDataParameter p12 = cmd.CreateParameter();
                p12.ParameterName = "@MobileNo";
                p12.Value         = airBooking.Contact.MobileNo;
                cmd.Parameters.Add(p12);


                IDbDataParameter p13 = cmd.CreateParameter();
                p13.ParameterName = "@PaymentRefernceNo";
                p13.Value         = airBooking.PaymentInfo.ReferenceNo;
                cmd.Parameters.Add(p13);

                IDbDataParameter p14 = cmd.CreateParameter();
                p14.ParameterName = "@TotalCost";
                p14.Value         = airBooking.TotalCost;
                cmd.Parameters.Add(p14);

                //Concatenate to send to database as a single string
                string passengerDetails = String.Empty;
                string name             = String.Empty;
                string gender           = String.Empty;
                string dob = String.Empty;

                foreach (Passenger p in airBooking.GetPassengers())
                {
                    name   = p.Name;
                    gender = p.Gender.ToString();
                    dob    = p.DateOfBirth.ToShortDateString();

                    passengerDetails += name + "|" + gender + "|" + dob + ";";
                }

                IDbDataParameter p15 = cmd.CreateParameter();
                p15.ParameterName = "@PassengerDetails";
                p15.Value         = passengerDetails;
                cmd.Parameters.Add(p15);

                IDbDataParameter bookingRefNo = cmd.CreateParameter();
                bookingRefNo.Size          = -1;
                bookingRefNo.ParameterName = "@BookingReferenceNumber";
                bookingRefNo.Direction     = ParameterDirection.Output;
                bookingRefNo.Value         = "";
                cmd.Parameters.Add(bookingRefNo);

                IDbDataParameter lastBookingId = cmd.CreateParameter();
                lastBookingId.ParameterName = "@LastBookingID";
                lastBookingId.Direction     = ParameterDirection.Output;
                lastBookingId.Value         = 0;
                cmd.Parameters.Add(lastBookingId);

                //Execute the command
                cmd.ExecuteNonQuery();

                //Get the values from the database
                bookingReferenceNo = bookingRefNo.Value.ToString();
                long bookingId = Convert.ToInt64(lastBookingId.Value);

                //Insert the schedules for a booking
                foreach (Schedule s in airBooking.TravelScheduleInfo.GetSchedules())
                {
                    try
                    {
                        InsertBookingSchedule(bookingId, s.ID, s.GetFlightCosts().FirstOrDefault().CostPerTicket, dbConnection);
                    }
                    catch (AirTravelBookingException)
                    {
                        throw;
                    }
                }
            }
            catch (AirTravelBookingException)
            {
                throw;
            }
            catch (DbException ex)
            {
                throw new AirTravelBookingException("Unable to insert air travel booking", ex);
            }
            catch (Exception ex)
            {
                throw new AirTravelBookingException("Unable to insert air travel booking", ex);
            }
            finally
            {
                if (dbConnection != null && dbConnection.State == ConnectionState.Open)
                {
                    dbConnection.Close();
                }
            }

            return(bookingReferenceNo);
        }
        protected void btnBook_Click(object sender, EventArgs e)
        {
            int            happyMiles = 0;
            MembershipUser mUser      = Membership.GetUser();
            decimal        travelCost = 0;
            string         userName   = "";

            try
            {
                int CardExpiryYear  = Convert.ToInt16(ddlccExpirationYear.SelectedItem.Value);
                int CardExpiryMonth = Convert.ToInt16(ddlccExpirationMonth.SelectedItem.Value);
                int cardType        = Convert.ToInt16(ddlccCardType.SelectedItem.Value);

                if (ValidatePaymentDetails(CardExpiryMonth, CardExpiryYear))
                {
                    TravelBooking travelbooking = (TravelBooking)Session["travelbooking"];
                    Card          _card         = new Card()
                    {
                        CardNo = txtCard_no.Text, Cvv2No = txtCvv.Text, Name = txtcard_holder.Text, ExpiryYear = CardExpiryYear, ExpiryMonth = CardExpiryMonth, CardType = (CardTypes)cardType
                    };

                    IBookingManager _bookingManager     = BookingManagerFactory.GetInstance().Create();
                    TravelBooking   travelbookingresult = null;

                    travelbookingresult = _bookingManager.ProcessAirTravelBooking(travelbooking, _card);

                    if (Request.IsAuthenticated)
                    {
                        //Added by Anand for updated travel miles
                        IHappyMiles travelMiles = new HappyMilesManager();

                        List <int> theAirlines = new List <int>();

                        //AirlineIDs for the onwared flights
                        FlightBooking flightBookingOnward = (FlightBooking)travelbooking.GetBookingForTravel(TravelDirection.OneWay);
                        if (flightBookingOnward != null)
                        {
                            theAirlines.Clear();
                            List <Schedule> theSchedules = flightBookingOnward.TravelScheduleInfo.GetSchedules();
                            if (theSchedules != null)
                            {
                                foreach (Schedule schedule in theSchedules)
                                {
                                    theAirlines.Add(schedule.FlightInfo.AirlineForFlight.Id);
                                }
                                if (mUser != null)
                                {
                                    userName = mUser.UserName;
                                    decimal insurance = 0;
                                    if (flightBookingOnward.Insurance != null)
                                    {
                                        insurance = flightBookingOnward.Insurance.Amount;
                                    }
                                    travelCost  = travelbooking.GetBookingForTravel(TravelDirection.OneWay).TotalCost - insurance;
                                    happyMiles += travelMiles.UpdateHappyMilesForUser(userName, theAirlines, (double)travelCost, flightBookingOnward.ReferenceNo);
                                }
                            }
                        }

                        if (travelbooking.IsReturnAvailable())
                        {
                            //AirlineIDs for the return flights
                            theAirlines.Clear();
                            FlightBooking   flightBookingReturn = (FlightBooking)travelbooking.GetBookingForTravel(TravelDirection.Return);
                            List <Schedule> theSchedules        = flightBookingReturn.TravelScheduleInfo.GetSchedules();
                            if (theSchedules != null)
                            {
                                foreach (Schedule schedule in theSchedules)
                                {
                                    theAirlines.Add(schedule.FlightInfo.AirlineForFlight.Id);
                                }
                                if (mUser != null)
                                {
                                    userName = mUser.UserName;
                                    decimal insurance = 0;
                                    if (flightBookingOnward.Insurance != null)
                                    {
                                        insurance = flightBookingOnward.Insurance.Amount;
                                    }
                                    travelCost  = travelbooking.GetBookingForTravel(TravelDirection.Return).TotalCost - insurance;
                                    happyMiles += travelMiles.UpdateHappyMilesForUser(userName, theAirlines, (double)travelCost, flightBookingReturn.ReferenceNo);
                                }
                            }
                        }

                        ((SiteMaster)Master).ShowHappyMilesForUser();
                        Session["happymiles"] = happyMiles;
                    }

                    Session["travelbooking"] = travelbookingresult;

                    Response.Redirect("~/booking/Payment_Success.aspx");
                }
            }
            catch (HappyTrip.Model.BusinessLayer.Search.FlightSeatsAvailabilityException ex)
            {
                lblUnSuccessful.Visible = true;
                lblUnSuccessful.Text    = ex.Message;
            }
            catch (PaymentProcessException ex)
            {
                lblUnSuccessful.Visible = true;
                lblUnSuccessful.Text    = ex.Message;
            }
            catch (InvalidBookingTypeException ex)
            {
                lblUnSuccessful.Visible = true;
                lblUnSuccessful.Text    = ex.Message;
            }
            catch (BookingException ex)
            {
                lblUnSuccessful.Visible = true;
                lblUnSuccessful.Text    = ex.Message;
            }
            catch (Exception)
            {
                lblUnSuccessful.Visible = true;
                lblUnSuccessful.Text    = "Unable to Book Tickets";
            }
        }
示例#9
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session.Count == 0)
            {
                Response.Redirect("~/Index.aspx");
            }
            if (!IsPostBack)
            {
                try
                {
                    #region Obtain the bookingObjects From Session
                    decimal       totalCost           = 0;
                    TravelBooking _travelBooking      = null;
                    FlightBooking flightbookingonward = null;
                    FlightBooking flightbookingreturn = null;
                    if (Session["travelbooking"] != null)
                    {
                        _travelBooking      = (TravelBooking)Session["travelbooking"];
                        flightbookingonward = (FlightBooking)_travelBooking.GetBookingForTravel(TravelDirection.OneWay);
                        flightbookingreturn = (FlightBooking)_travelBooking.GetBookingForTravel(TravelDirection.Return);
                    }
                    else
                    {
                        Response.Redirect("~/Index.aspx");
                    }
                    if (flightbookingonward != null)
                    {
                        int NoOfSeats = flightbookingonward.NoOfSeats;

                        List <Passenger> lstPassenger = flightbookingonward.GetPassengers();;

                        rptrPassengerInfo.DataSource = lstPassenger;
                        rptrPassengerInfo.DataBind();

                        rptrOnwardFlightInfo.DataSource = flightbookingonward.TravelScheduleInfo.GetSchedules();
                        rptrOnwardFlightInfo.DataBind();

                        totalCost = flightbookingonward.TotalCost;

                        lblHeaderFromCity.Text = flightbookingonward.TravelScheduleInfo.GetSchedules()[0].RouteInfo.FromCity.Name;
                        lblHeaderToCity.Text   = flightbookingonward.TravelScheduleInfo.GetSchedules()[0].RouteInfo.ToCity.Name;
                        lblAdults.Text         = flightbookingonward.NoOfSeats.ToString();

                        lblHeaderDepart.Text = flightbookingonward.DateOfJourney.ToString("ddd, dd MMM, yyyy");

                        lblHeaderDateSeparator.Visible = false;
                        if (_travelBooking.IsReturnAvailable())
                        {
                            lblHeaderDateSeparator.Visible = true;
                        }

                        //Fill Contacts details
                        lblName.Text         = flightbookingonward.Contact.ContactName;
                        lblAddressline1.Text = flightbookingonward.Contact.MobileNo;
                        lblState.Text        = flightbookingonward.Contact.State;
                        lblCity.Text         = flightbookingonward.Contact.City;
                        lblEmail.Text        = flightbookingonward.Contact.Email;
                        lblMobno.Text        = flightbookingonward.Contact.MobileNo;
                        lblPhno.Text         = flightbookingonward.Contact.PhoneNo;
                    }

                    if (flightbookingreturn != null)
                    {
                        int NoOfSeats = flightbookingreturn.NoOfSeats;

                        rptrReturnFlightInfo.DataSource = flightbookingreturn.TravelScheduleInfo.GetSchedules();
                        rptrReturnFlightInfo.DataBind();

                        divReturn.Visible = true;

                        totalCost = totalCost + flightbookingreturn.TotalCost;

                        lblHeaderReturn.Text = flightbookingreturn.DateOfJourney.ToString("ddd, dd MMM, yyyy");
                    }

                    //Insurance Display
                    decimal insuranceOnwardAmount = 0;
                    decimal insuranceReturnAmount = 0;
                    if (flightbookingonward.Insurance != null)
                    {
                        insuranceOnwardAmount = flightbookingonward.Insurance.Amount;

                        if (flightbookingreturn != null && flightbookingreturn.Insurance != null)
                        {
                            insuranceReturnAmount = flightbookingreturn.Insurance.Amount;
                        }

                        lblInsuranceText.Text  = "You have opted to go for travel insurance for the amount : ";
                        lblInsuranceValue.Text = "Onward Journey : INR " + (insuranceOnwardAmount / flightbookingonward.NoOfSeats) + " /- Per Passenger ";

                        if (insuranceReturnAmount > 0)
                        {
                            lblInsuranceValue.Text += "-- Return Journey : INR " + (insuranceReturnAmount / flightbookingreturn.NoOfSeats) + " /- Per Passenger ";
                        }

                        lblInsuranceText.Visible  = true;
                        lblInsuranceValue.Visible = true;
                    }
                    else
                    {
                        lblInsuranceValue.Text    = "INR 0.0";
                        lblInsuranceValue.Visible = true;
                    }

                    lblTotalPrice.Text = "INR " + totalCost.ToString();

                    lblGrandTotal.Text = "INR " + (totalCost + insuranceOnwardAmount + insuranceReturnAmount).ToString();

                    #endregion
                }
                catch (Exception)
                {
                    lblHeaderDepart.Text = "Sorry !!! Unable to display details";
                }
            }
        }
示例#10
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                try
                {
                    #region Obtain the bookingObjects From Session
                    decimal       TotalCost           = 0;
                    TravelBooking _travelBooking      = null;
                    FlightBooking flightbookingonward = null;
                    FlightBooking flightbookingreturn = null;
                    if (Session["travelbooking"] != null)
                    {
                        _travelBooking      = (TravelBooking)Session["travelbooking"];
                        flightbookingonward = (FlightBooking)_travelBooking.GetBookingForTravel(TravelDirection.OneWay);
                        flightbookingreturn = (FlightBooking)_travelBooking.GetBookingForTravel(TravelDirection.Return);
                    }
                    if (flightbookingonward != null)
                    {
                        FlightBooking flightbooking = flightbookingonward;
                        int           NoOfSeats     = flightbooking.NoOfSeats;

                        List <Passenger> lstPassenger = flightbooking.GetPassengers();;

                        rptrPassengerInfo.DataSource = lstPassenger;
                        rptrPassengerInfo.DataBind();

                        rptrOnwardFlightInfo.DataSource = flightbooking.TravelScheduleInfo.GetSchedules();
                        rptrOnwardFlightInfo.DataBind();

                        TotalCost = flightbooking.TotalCost;

                        lblHeaderFromCity.Text = flightbookingonward.TravelScheduleInfo.GetSchedules()[0].RouteInfo.FromCity.Name;
                        lblHeaderToCity.Text   = flightbookingonward.TravelScheduleInfo.GetSchedules()[0].RouteInfo.ToCity.Name;
                        lblAdults.Text         = flightbookingonward.NoOfSeats.ToString();

                        lblHeaderDepart.Text = flightbookingonward.DateOfJourney.ToString("ddd, dd MMM, yyyy");

                        lblHeaderDateSeparator.Visible = false;
                        if (_travelBooking.IsReturnAvailable())
                        {
                            lblHeaderDateSeparator.Visible = true;
                        }

                        //Fill Contacts details
                        lblName.Text         = flightbooking.Contact.ContactName;
                        lblAddressline1.Text = flightbooking.Contact.MobileNo;
                        lblState.Text        = flightbooking.Contact.State;
                        lblCity.Text         = flightbooking.Contact.City;
                        lblEmail.Text        = flightbooking.Contact.Email;
                        lblMobno.Text        = flightbooking.Contact.MobileNo;
                        lblPhno.Text         = flightbooking.Contact.PhoneNo;
                    }

                    if (flightbookingreturn != null)
                    {
                        FlightBooking flightbooking = flightbookingreturn;
                        int           NoOfSeats     = flightbooking.NoOfSeats;

                        rptrReturnFlightInfo.DataSource = flightbooking.TravelScheduleInfo.GetSchedules();
                        rptrReturnFlightInfo.DataBind();

                        divReturn.Visible = true;

                        TotalCost = TotalCost + flightbooking.TotalCost;

                        lblHeaderReturn.Text = flightbookingreturn.DateOfJourney.ToString("ddd, dd MMM, yyyy");
                    }

                    lblTotalPrice.Text = TotalCost.ToString();
                    #endregion
                }
                catch (Exception)
                {
                    lblHeaderDepart.Text = "Sorry !!! Unable to display details";
                }
            }
        }
        /// <summary>
        /// Inserts into database the booking for air travel
        /// </summary>
        /// <param name="newBooking"></param>
        /// <param name="dbConnection"></param>
        /// <exception cref="AirTravelBookingException">Throws the AirTravelBookingException, if unable to store a booking</exception>
        /// <returns>Returns the booking reference number</returns>
        public string MakeBooking(Booking newBooking, IDbConnection dbConnection, IDbTransaction tran)
        {
            string bookingReferenceNo = string.Empty;

            //Downcast to flight booking
            FlightBooking airBooking = (FlightBooking)newBooking;

            try
            {
                //Write code to store data into database
                IDbCommand command = CreateCommand(dbConnection, "BookFlightTicket", CommandType.StoredProcedure, tran);

                command.Parameters.Add(new SqlParameter()
                {
                    ParameterName = "@TypeID", DbType = DbType.Int32, Value = (int)airBooking.BookingType
                });
                command.Parameters.Add(new SqlParameter()
                {
                    ParameterName = "@DateOfJourney", DbType = DbType.DateTime, Value = airBooking.DateOfJourney
                });
                command.Parameters.Add(new SqlParameter()
                {
                    ParameterName = "@NoOfSeats", DbType = DbType.Int32, Value = airBooking.NoOfSeats
                });
                command.Parameters.Add(new SqlParameter()
                {
                    ParameterName = "@ClassID", DbType = DbType.Int32, Value = (int)airBooking.Class.ClassInfo
                });
                command.Parameters.Add(new SqlParameter()
                {
                    ParameterName = "@ContactName", DbType = DbType.String, Value = airBooking.Contact.ContactName
                });
                command.Parameters.Add(new SqlParameter()
                {
                    ParameterName = "@Address", DbType = DbType.String, Value = airBooking.Contact.Address
                });
                command.Parameters.Add(new SqlParameter()
                {
                    ParameterName = "@City", DbType = DbType.String, Value = airBooking.Contact.City
                });
                command.Parameters.Add(new SqlParameter()
                {
                    ParameterName = "@State", DbType = DbType.String, Value = airBooking.Contact.State
                });
                command.Parameters.Add(new SqlParameter()
                {
                    ParameterName = "@PinCode", DbType = DbType.String, Value = "000000"
                });
                command.Parameters.Add(new SqlParameter()
                {
                    ParameterName = "@Email", DbType = DbType.String, Value = airBooking.Contact.Email
                });
                command.Parameters.Add(new SqlParameter()
                {
                    ParameterName = "@PhoneNo", DbType = DbType.String, Value = airBooking.Contact.PhoneNo
                });
                command.Parameters.Add(new SqlParameter()
                {
                    ParameterName = "@MobileNo", DbType = DbType.String, Value = airBooking.Contact.MobileNo
                });
                command.Parameters.Add(new SqlParameter()
                {
                    ParameterName = "@PaymentRefernceNo", DbType = DbType.String, Value = airBooking.PaymentInfo.ReferenceNo
                });
                command.Parameters.Add(new SqlParameter()
                {
                    ParameterName = "@TotalCost", DbType = DbType.Decimal, Value = airBooking.TotalCost
                });
                if (airBooking.Insurance != null)
                {
                    command.Parameters.Add(new SqlParameter()
                    {
                        ParameterName = "@Insurance", DbType = DbType.Decimal, Value = airBooking.Insurance.Amount
                    });
                }
                else
                {
                    command.Parameters.Add(new SqlParameter()
                    {
                        ParameterName = "@Insurance", DbType = DbType.Decimal, Value = 0
                    });
                }

                //Concatenate to send to database as a single string
                string passengerDetails = String.Empty;
                string name             = String.Empty;
                string gender           = String.Empty;
                string dob = String.Empty;

                foreach (Passenger p in airBooking.GetPassengers())
                {
                    name   = p.Name;
                    gender = p.Gender.ToString();
                    dob    = p.DateOfBirth.ToShortDateString();

                    passengerDetails += name + "|" + gender + "|" + dob + ";";
                }

                command.Parameters.Add(new SqlParameter()
                {
                    ParameterName = "@PassengerDetails", DbType = DbType.String, Value = passengerDetails
                });

                SqlParameter prmBookingReferenceNumber = new SqlParameter()
                {
                    ParameterName = "@BookingReferenceNumber", DbType = DbType.String, Size = 100, Value = 100, Direction = ParameterDirection.Output
                };
                command.Parameters.Add(prmBookingReferenceNumber);

                SqlParameter prmLastBookingID = new SqlParameter()
                {
                    ParameterName = "@LastBookingID", DbType = DbType.Int64, Value = 0, Direction = ParameterDirection.Output
                };
                command.Parameters.Add(prmLastBookingID);

                //Execute the command
                command.ExecuteNonQuery();

                //Get the values from the database
                bookingReferenceNo = prmBookingReferenceNumber.Value.ToString();
                long bookingId = Convert.ToInt64(prmLastBookingID.Value);

                //Insert the schedules for a booking
                foreach (Schedule s in airBooking.TravelScheduleInfo.GetSchedules())
                {
                    InsertBookingSchedule(bookingId, s.ID, s.GetFlightCosts().FirstOrDefault().CostPerTicket, dbConnection, tran);
                }
            }
            catch (AirTravelBookingException)
            {
                throw;
            }
            catch (DbException ex)
            {
                throw new AirTravelBookingException("Unable to insert air travel booking", ex);
            }
            catch (Exception ex)
            {
                throw new AirTravelBookingException("Unable to insert air travel booking", ex);
            }

            return(bookingReferenceNo);
        }
示例#12
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);
        }