예제 #1
0
        /// <summary>
        /// Inserts into database the booking information for different types
        /// </summary>
        /// <param name="newBooking"></param>
        /// <exception cref="BookingDAOException">Throws the BookingDAOException, if unable to store a booking</exception>
        /// <returns>Returns the booking reference number</returns>
        public string MakeBooking(HappyTrip.Model.Entities.Transaction.Booking newBooking)
        {
            string bookingReferenceNo = string.Empty;

            try
            {
                #region Old Commented Code
                //Get the database connection from DAO class that is inherited
                //Database dbConnection = GetDatabaseConnection();
                #endregion

                //Get the database connection from DAO class that is inherited
                IDbConnection dbConnection = GetConnection();

                //Delegate to the corresponding dao implementation created during call to get instance
                bookingReferenceNo = daoImpl.MakeBooking(newBooking, dbConnection);

                if ((newBooking.UserName.Equals("Anonymous", StringComparison.OrdinalIgnoreCase)))
                {
                    try
                    {
                        StoreBookingForUser(bookingReferenceNo, newBooking.UserName, dbConnection);
                    }
                    catch (BookingDAOException)
                    {
                        throw;
                    }
                }
            }
            catch (Common.ConnectToDatabaseException ex)
            {
                throw new BookingDAOException("Unable to store Booking Information", ex);
            }
            catch (BookingDAOException)
            {
                throw;
            }
            catch (AirTravelBookingException ex)
            {
                throw new BookingDAOException("Unable to store Air Travel Booking Information", ex);
            }
            catch (DbException ex)
            {
                throw new BookingDAOException("Unable to store Booking Information", ex);
            }
            catch (Exception ex)
            {
                throw new BookingDAOException("Unable to store Booking Information", ex);
            }

            return(bookingReferenceNo);
        }
예제 #2
0
        /// <summary>
        /// Inserts into database the booking information for different types
        /// </summary>
        /// <param name="newBooking"></param>
        /// <exception cref="BookingDAOException">Throws the BookingDAOException, if unable to store a booking</exception>
        /// <returns>Returns the booking reference number</returns>
        public string MakeBooking(HappyTrip.Model.Entities.Transaction.Booking newBooking)
        {
            IDbTransaction tran = null;
            string         bookingReferenceNo = string.Empty;

            try
            {
                //Get the database connection from DAO class that is inherited
                using (IDbConnection dbConnection = GetConnection())
                {
                    tran = dbConnection.BeginTransaction();

                    //Delegate to the corresponding dao implementation created during call to get instance
                    bookingReferenceNo = daoImpl.MakeBooking(newBooking, dbConnection, tran);

                    if (!newBooking.UserName.Equals("Anonymous", StringComparison.OrdinalIgnoreCase))
                    {
                        StoreBookingForUser(bookingReferenceNo, newBooking.UserName, dbConnection, tran);
                    }

                    tran.Commit();
                    dbConnection.Close();
                }
            }
            catch (Common.ConnectToDatabaseException ex)
            {
                RollbackTransactionAndCloseConnection(tran);
                throw new BookingDAOException("Unable to store Booking Information", ex);
            }
            catch (BookingDAOException)
            {
                RollbackTransactionAndCloseConnection(tran);
                throw;
            }
            catch (AirTravelBookingException ex)
            {
                RollbackTransactionAndCloseConnection(tran);
                throw new BookingDAOException("Unable to store Air Travel Booking Information", ex);
            }
            catch (DbException ex)
            {
                RollbackTransactionAndCloseConnection(tran);
                throw new BookingDAOException("Unable to store Booking Information", ex);
            }
            catch (Exception ex)
            {
                RollbackTransactionAndCloseConnection(tran);
                throw new BookingDAOException("Unable to store Booking Information", ex);
            }

            return(bookingReferenceNo);
        }