Esempio n. 1
0
        /// <summary>
        /// 1. Check for nearest available cab. if cab is not available then return -1
        /// 2. if cabId is greater than 0 then a new booking with booking id = bookingDetailsList count
        /// set cab availability false and return this new booking id
        /// (We consider 0 also valid booking id. since list index starts with 0)
        /// We can also handle this. but for simplicity we are not considering this
        /// </summary>
        /// <param name="customerSource">customer source location</param>
        /// <param name="customerDestination">customer destination location</param>
        /// <param name="customerId">customer id</param>
        /// <param name="tripStartTime">trip start time</param>
        /// <param name="isPink">pink cab is needed or not</param>
        /// <returns>booking id if cab is booked otherwise return -1</returns>
        public static int BookCab(Location customerSource, Location customerDestination, int customerId, DateTime tripStartTime, bool isPink = false)
        {
            int cabId = GetNearestAvailableCab(customerSource, isPink);

            if (cabId < 0)
            {
                return(-1);
            }
            int newBookingId = _bookingDetails.Count;
            // new booking Id will be size of booking details list
            var bookingDetail = new BookingDetail
            {
                Id            = newBookingId,
                CabId         = cabId,
                CustomerId    = customerId,
                Source        = customerSource,
                Destination   = customerDestination,
                TripStartTime = tripStartTime
            };

            _bookingDetails.Add(bookingDetail);
            SetAvailabilityOfCab(cabId, false);
            return(newBookingId);
        }