public BookCarRequestModel(int _carId, string _customerId, DestinationOrigin _customerCurrentPosition, DestinationOrigin _customerDestinationPosition)
 {
     car_id     = _carId;
     customerId = _customerId;
     customerCurrentPosition     = _customerCurrentPosition;
     customerDestinationPosition = _customerDestinationPosition;
 }
 public BookCarRequestModel()
 {
     car_id     = 0;
     customerId = string.Empty;
     customerCurrentPosition     = new DestinationOrigin();
     customerDestinationPosition = new DestinationOrigin();
 }
        public List <DestinationOrigin> GetDestinationOrigins()
        {
            List <DestinationOrigin> originFlights = new List <DestinationOrigin>();

            try
            {
                var conn = _dbContext.ConnectToDB();

                var rdr = _dbContext.ExecuteQuery("SELECT dest , COUNT(dest), origin FROM flights WHERE dest IN (select * FROM (Select dest FROM flights GROUP BY dest ORDER BY COUNT(dest) DESC LIMIT 0,10) AS t1) GROUP BY dest, origin ORDER BY origin, dest;", conn);

                var j = 0;
                while (rdr.Read() && j < 3)
                {
                    var originFlight = new DestinationOrigin {
                        Origin = rdr.GetString(2)
                    };
                    var origin  = originFlight.Origin;
                    var flights = new List <DestinationFlights>();
                    do
                    {
                        var flight = new DestinationFlights
                        {
                            Destination = rdr.GetString(0),
                            count       = rdr.GetInt16(1)
                        };
                        flights.Add(flight);
                        origin = rdr.GetString(2);
                    } while (rdr.Read() && rdr.GetString(2) == origin);

                    originFlight.Flights = flights;
                    originFlights.Add(originFlight);

                    j++;
                }

                _dbContext.CloseConnections(rdr, conn);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

            return(originFlights);
        }
        public BookCarResponseModel bookCar(BookCarRequestModel bookCarRequestModel)
        {
            if (lstCars.Where(lc => lc.bookedBy == bookCarRequestModel.customerId).Count() != 0)
            {
                return(new BookCarResponseModel(string.Format("{0} is already booked", bookCarRequestModel.car_id), false));
            }
            Car car = lstCars.Find(c => c.id == bookCarRequestModel.car_id && c.isBooked == false);

            if (car != null)
            {
                car.isBooked = true;
                car.bookedBy = bookCarRequestModel.customerId;
                car.lstDestinationPosition.Clear();

                DestinationOrigin dOrigin  = new DestinationOrigin(bookCarRequestModel.customerCurrentPosition.x, bookCarRequestModel.customerCurrentPosition.y, false);
                DestinationOrigin dOrigin1 = new DestinationOrigin(bookCarRequestModel.customerDestinationPosition.x, bookCarRequestModel.customerDestinationPosition.y, false);

                car.lstDestinationPosition.Add(dOrigin);
                car.lstDestinationPosition.Add(dOrigin1);
                return(new BookCarResponseModel(string.Format("{0} is booked for {1}", bookCarRequestModel.car_id, bookCarRequestModel.customerId), true));
            }
            return(new BookCarResponseModel(string.Format("{0} is already booked", bookCarRequestModel.car_id), false));
        }