public int AvailableSeats(Ride ride, string from, string to)
        {
            List <int>    Seats  = new List <int>();
            List <string> Points = new List <string>();

            Points.Add(ride.PickUp.ToLower());
            Seats.Add(0);

            IViaPointService viaPointService = new ViaPointService(configuration);
            List <ViaPoint>  ViaPoints       = viaPointService.GetAllViaPoints(ride.Id);
            int viaPointsCount = ViaPoints.Count;

            for (int i = 0; i < viaPointsCount; i++)
            {
                Points.Add("");
            }
            foreach (ViaPoint point in ViaPoints)
            {
                Points[point.Index] = point.Name;
                Seats.Add(0);
            }
            Points.Add(ride.Drop.ToLower());

            int fromIndex = Points.IndexOf(from.ToLower());
            int toIndex   = Points.IndexOf(to.ToLower());

            if (fromIndex == -1 || toIndex == -1)
            {
                return(0);
            }

            int numberOfBookings = 0;

            for (int i = 0; i < toIndex; i++)
            {
                for (int j = i + 1; j < Points.Count; j++)
                {
                    numberOfBookings = GetBookingsCount(ride.Id, Points[i], Points[j]);
                    if (numberOfBookings == 0)
                    {
                        continue;
                    }
                    for (int k = i; k < j; k++)
                    {
                        Seats[k] += numberOfBookings;
                    }
                }
            }

            int max = 0;

            for (int i = fromIndex; i < toIndex; i++)
            {
                if (Seats[i] > max)
                {
                    max = Seats[i];
                }
            }
            return(ride.NumberOfSeats - max);
        }
        public List <Ride> FindRide(string from, string to)
        {
            from = from.ToLower();
            to   = to.ToLower();
            List <Ride> requiredRides  = new List <Ride>();
            int         availableSeats = 0;

            IBookingService  bookingService  = new BookingService(configuration);
            IViaPointService viaPointService = new ViaPointService(configuration);

            string          query           = "select * from Ride";
            ExtensionObject extensionObject = new ExtensionObject()
            {
                Query            = query,
                ConnectionString = connectionString
            };

            List <Ride> rides = extensionObject.GetAllItems <Ride>();

            foreach (Ride ride in rides)
            {
                availableSeats = bookingService.AvailableSeats(ride, from, to);
                if (availableSeats > 0)
                {
                    ride.AvailableSeats = availableSeats;
                    query = "select id,name,phoneNumber from [User] where Id= (select publisherId from Ride where Id='" + ride.Id + "')";
                    ExtensionObject publisherExtensionObject = new ExtensionObject()
                    {
                        Query            = query,
                        ConnectionString = connectionString
                    };

                    ride.Publisher = publisherExtensionObject.GetItem <User>();
                    query          = "select value from Status where Id=(select statusId from Ride where Id='" + ride.Id + "')";
                    ExtensionObject statusExtensionObject = new ExtensionObject()
                    {
                        Query            = query,
                        ConnectionString = connectionString
                    };
                    ride.Status = statusExtensionObject.GetItem <Status>();
                    requiredRides.Add(ride);
                }
            }
            return(requiredRides);
        }