Example #1
0
        /// <summary>
        /// function to add routes to the database
        /// </summary>
        public bool AddRoutes(string journeyID)
        {
            if (bookingDataAccess.GetBookingsOfJourney(journeyID).Count != 0)
            {
                return(false);
            }
            routeDataAccess.DeleteAllRoute(journeyID);
            Journey      journey   = journeyBusiness.GetJourney(journeyID);
            List <Route> routeList = new List <Route>();

            string departureId = "";
            float  priceA      = 0;
            float  priceB      = 0;

            // Add all routes [Departure to checkpoints/destination] in list
            foreach (Checkpoint c in journey.Journey_Checkpoints)
            {
                if (c.Type.Equals("departure"))
                {
                    string departure = c.Checkpoint_ID;
                    departureId = c.Checkpoint_ID;

                    foreach (Checkpoint d in journey.Journey_Checkpoints)
                    {
                        if (d.Type.Equals("stopover") || d.Type.Equals("destination"))
                        {
                            routeList.Add(new Route("", departure, d.Checkpoint_ID, d.Price, journey.Available_Seats, journey));
                        }
                    }
                }
            }

            // Add all routes [checkpoint to checkpoints/destination] in list
            foreach (Checkpoint c in journey.Journey_Checkpoints)
            {
                if (c.Type.Equals("stopover"))
                {
                    string departure = c.Checkpoint_ID;

                    foreach (Checkpoint d in journey.Journey_Checkpoints)
                    {
                        if (d.Type.Equals("stopover") || d.Type.Equals("destination"))
                        {
                            if (!c.Equals(d))
                            {
                                foreach (Route route in routeList)
                                {
                                    if (route.Departure.Equals(departureId) && route.Destination.Equals(d.Checkpoint_ID))
                                    {
                                        priceA = route.Price;
                                    }

                                    if (route.Departure.Equals(departureId) && route.Destination.Equals(c.Checkpoint_ID))
                                    {
                                        priceB = route.Price;
                                    }
                                }

                                float newPrice = priceA - priceB;

                                if (newPrice > 0)
                                {
                                    routeList.Add(new Route("", departure, d.Checkpoint_ID, newPrice, journey.Available_Seats, journey));
                                }
                            }
                        }
                    }
                }
            }
            return(routeDataAccess.AddRoutes(routeList));
        }
 public List <Booking> GetBookingsOfJourney(string journeyID)
 {
     return(bookingDataAccess.GetBookingsOfJourney(journeyID));
 }