Example #1
0
        private void btnApply_Click(object sender, EventArgs e)
        {
            if (rbOne.Checked)
            {
                outboundDate = dtpOutbound.Value.Date;
                qOutbound    = flight.GetFlightDetails(cbFrom.Text, cbTo.Text, cbCabin.Text, outboundDate);
                if (qOutbound.Count > 0)
                {
                    if (qOutbound.Select(x => x.FlightNumber).Distinct().Count() > 1)
                    {
                        FlightDetails flight = new FlightDetails
                        {
                            From          = cbFrom.Text,
                            To            = cbTo.Text,
                            Date          = qOutbound[0].Date,
                            Time          = qOutbound[0].Time,
                            CabinPrice    = qOutbound.Sum(x => x.CabinPrice),
                            FlightNumber  = string.Join(" - ", qOutbound.Select(x => x.FlightNumber).ToList()),
                            NumberOfStops = qOutbound.Count - 1
                        };

                        qOutbound = new List <FlightDetails> {
                            flight
                        };
                    }
                }
                else
                {
                    MessageBox.Show("No Flights to the destination found (pick either different route, date, or even tick 'One way')");
                }

                q[0] = qOutbound;
                q[1] = null;
                DisplayOutbound();
            }
            else
            {
                outboundDate = dtpOutbound.Value.Date;
                returnDate   = dtpReturn.Value.Date;
                qOutbound    = flight.GetFlightDetails(cbFrom.Text, cbTo.Text, cbCabin.Text, outboundDate);
                qReturn      = flight.GetFlightDetails(cbTo.Text, cbFrom.Text, cbCabin.Text, returnDate);

                if (qOutbound.Count > 0)
                {
                    if (qOutbound.Select(x => x.FlightNumber).Distinct().Count() > 1)
                    {
                        FlightDetails flight = new FlightDetails
                        {
                            From          = cbFrom.Text,
                            To            = cbTo.Text,
                            Date          = qOutbound[0].Date,
                            Time          = qOutbound[0].Time,
                            CabinPrice    = qOutbound.Sum(x => x.CabinPrice),
                            FlightNumber  = string.Join(" - ", qOutbound.Select(x => x.FlightNumber).ToList()),
                            NumberOfStops = qOutbound.Count - 1
                        };

                        qOutbound = new List <FlightDetails> {
                            flight
                        };
                    }
                }
                else
                {
                    MessageBox.Show("No Flights to destination found");
                }

                if (qReturn.Count > 0)
                {
                    if (qReturn.Select(x => x.FlightNumber).Distinct().Count() > 1)
                    {
                        FlightDetails flight = new FlightDetails
                        {
                            From          = cbTo.Text,
                            To            = cbFrom.Text,
                            Date          = qReturn[0].Date,
                            Time          = qReturn[0].Time,
                            CabinPrice    = qReturn.Sum(x => x.CabinPrice),
                            FlightNumber  = string.Join(" - ", qReturn.Select(x => x.FlightNumber).ToList()),
                            NumberOfStops = qReturn.Count - 1
                        };

                        qReturn = new List <FlightDetails> {
                            flight
                        };
                    }
                }
                else
                {
                    MessageBox.Show("No Flights to home found (pick either different route, date, or even tick 'One way')");
                }

                q[0] = qOutbound;
                q[1] = qReturn;
                DisplayOutbound();
                DisplayReturn();
            }
        }