Example #1
0
        public List <AdminViewFlight> searchFlight(SearchFlight search)
        {
            List <AdminViewFlight> list = new List <AdminViewFlight>();

            if (search.Date == "")
            {
                var f = new AdminViewFlight();
                f.ID = 0;
                list.Add(f);
                return(list);
            }
            else
            {
                var f = new AdminViewFlight()
                {
                    ID              = 1,
                    Departure       = "Oslo",
                    DepartureTime   = "00:00",
                    Destination     = "Bardufoss",
                    DestinationTime = "00:00",
                    Airplane        = "Boeing737",
                    ClassType       = "Økonomi",
                    Price           = 500,
                    Seats           = 500,
                    TravelDate      = "00/00/00"
                };
                list.Add(f);
                list.Add(f);
                list.Add(f);
                return(list);
            }
        }
Example #2
0
        public List <SearchFlight> GetFlightDetails(string fldate, string source, string destination)
        {
            List <SearchFlight> details = new List <SearchFlight>();

            conn.Open();
            cmdFetchFlightDetails = new SqlCommand("proc_SearchFlight", conn);
            cmdFetchFlightDetails.Parameters.Add("@date", SqlDbType.VarChar, 10);
            cmdFetchFlightDetails.Parameters.Add("@source", SqlDbType.VarChar, 20);
            cmdFetchFlightDetails.Parameters.Add("@destination", SqlDbType.VarChar, 20);
            cmdFetchFlightDetails.CommandType         = CommandType.StoredProcedure;
            cmdFetchFlightDetails.Parameters[0].Value = fldate;
            cmdFetchFlightDetails.Parameters[1].Value = source;
            cmdFetchFlightDetails.Parameters[2].Value = destination;
            SqlDataReader drFlightDetails = cmdFetchFlightDetails.ExecuteReader();
            SearchFlight  search          = null;

            //if (drFlightDetails.HasRows == false)
            //    throw new NoFlightInDatabaseException();
            while (drFlightDetails.Read())
            {
                search               = new SearchFlight();
                search.Flightid      = drFlightDetails[0].ToString();
                search.Departuretime = drFlightDetails[1].ToString();
                search.Arrivaltime   = drFlightDetails[2].ToString();
                search.Duration      = drFlightDetails[3].ToString();
                search.Fare          = drFlightDetails[4].ToString();
                details.Add(search);
            }
            return(details);
        }
Example #3
0
        public async Task <IActionResult> SearchFlight(SearchFlight vm)
        {
            //var to keep search input for flight results use
            var searchFlightTemp = new SearchFlight
            {
                OriginID     = vm.OriginID,
                DestID       = vm.DestID,
                WaySelection = vm.WaySelection,
                DepartDate   = vm.DepartDate,
                ReturnDate   = vm.ReturnDate
            };

            _globalRepo.SaveObjToSessionJSON <SearchFlight>("searchFlightTemp", searchFlightTemp);

            HttpContext.Session.SetInt32("adultNum", vm.AdultNum);
            HttpContext.Session.SetInt32("childrenNum", vm.ChildrenNum);

            //get the result of search input
            var result = await _flightRepo.GetBySearchInput(vm);

            //subscribe to signalR real time update of item addition to Booking Table
            //_bookingRepo.subscribeBookingAdd();

            //copy and bring over variables needed for next view
            result.OriginName = vm.OriginName;
            result.DestName   = vm.DestName;

            return(View("FlightResults", result));
        }
Example #4
0
        public async Task <FlightsInputsVM> GetBySearchInput(SearchFlight vm)
        {
            using (IDbConnection conn = Connection)
            {
                try
                {
                    string sQuery = $"SELECT * FROM {Flight.tableName} WHERE OriginLocID = @OriginId AND DestLocID = @DestId AND CAST(DepartDateTime AS DATE) = @DepartDate;";
                    //string sQuery = "SELECT * FROM Flights AS f INNER JOIN FlightSeatTypes AS fs ON f.FlightSeatTypeID = fs.ID AND f.OriginLocID = @OriginId AND f.DestLocID = @DestId AND CAST(f.DepartDateTime AS DATE) >= @DepartDate;";
                    conn.Open();
                    var flights = new FlightsInputsVM();
                    flights.GoFlights = await conn.QueryAsync <Flight>(sQuery, new { OriginId = vm.OriginID, DestId = vm.DestID, DepartDate = vm.DepartDate });

                    //if return flight option selected
                    if (vm.WaySelection == 2 && vm.ReturnDate != null && vm.ReturnDate.ToShortDateString() != "1/1/0001")
                    {
                        flights.ReturnFlights = await conn.QueryAsync <Flight>(sQuery, new { OriginId = vm.DestID, DestId = vm.OriginID, DepartDate = vm.ReturnDate });
                    }
                    return(flights);
                }
                catch (Exception)
                {
                    throw;
                }
                finally
                {
                    conn.Close();
                }
            }
        }
        public void getSearchResults()
        {
            //Create class instance which has six parameters
            SearchFlight SearchClassInstance = new SearchFlight(Session["source"].ToString(), Session["destination"].ToString(),
                                                                Session["travelClass"].ToString(), Session["dateOfJourney"].ToString(),
                                                                Convert.ToInt32(Session["numberOfAdults"]), Convert.ToInt32(Session["numberOfChildren"]));



            //Search flight results of one way stored in a data table
            DataTable dtSearchFlightsResults = new DataTable();

            dtSearchFlightsResults = SearchClassInstance.SearchFlights();


            //Store dtSearchFlights as a session variable
            Session["dtSearchFlightResults"] = dtSearchFlightsResults;

            //Search flight results of round trip stored in a data table
            if (Session["tripType"].ToString().Equals("Round Trip"))
            {
                Session["dateOfJourney"] = txtDateOfJourney.Text;
                Session["dateOfReturn"]  = txtDateOfReturn.Text;
                var SearchClassInstanceRoundTrip = new SearchFlight(Session["destination"].ToString(), Session["source"].ToString(),
                                                                    Session["travelClass"].ToString(), Session["dateOfReturn"].ToString(),
                                                                    Convert.ToInt32(Session["numberOfAdults"]), Convert.ToInt32(Session["numberOfChildren"])
                                                                    );

                DataTable dtSearchFlightsResultsRoundTrip = new DataTable();
                dtSearchFlightsResultsRoundTrip = SearchClassInstanceRoundTrip.SearchFlights();

                //Store dtSearchFlights as a session variable
                Session["dtSearchFlightResultsRoundTrip"] = dtSearchFlightsResultsRoundTrip;
            }
        }
        public void TestFlightsExpectedResults()
        {
            SearchFlightModel inputSearch = new SearchFlightModel()
            {
                Origin = "LHR", Destination = "BOS"
            };

            List <SearchFlightModel> expectedResult = new List <SearchFlightModel>();
            SearchFlight             source         = new SearchFlight();

            expectedResult = source.searchFlighsByOriginDestination(inputSearch);

            searchFlightsController controller = new searchFlightsController();
            var view = controller.Index(inputSearch) as ViewResult;
            List <SearchFlightModel> actualResult = (List <SearchFlightModel>)view.ViewData.Model;

            Assert.AreEqual(expectedResult.Count, actualResult.Count);
            if (expectedResult.Count > 0)
            {
                for (int i = 0; i >= expectedResult.Count; i++)
                {
                    Assert.AreEqual(expectedResult[i].Origin, actualResult[i].Origin);
                    Assert.AreEqual(expectedResult[i].DepartureTime, actualResult[i].DepartureTime);
                    Assert.AreEqual(expectedResult[i].Destination, actualResult[i].DestinationTime);
                    Assert.AreEqual(expectedResult[i].DestinationTime, actualResult[i].DestinationTime);
                    Assert.AreEqual(expectedResult[i].Price, actualResult[i].Price);
                }
            }
        }
Example #7
0
        public ActionResult Index(SearchFlightModel inputSearch)
        {
            if (ModelState.IsValid)
            {
                List <SearchFlightModel> result = new List <SearchFlightModel>();

                SearchFlight source = new SearchFlight();
                result = source.searchFlighsByOriginDestination(inputSearch);

                ViewBag.NoRecordFound = false;
                //check flight count if its zero then message is created & if its greater than zero, flight list will be display on view.
                if (result.Count <= 0)
                {
                    ViewBag.NoRecordFound = true;
                    ViewBag.Message       = "No Flights Found for " + inputSearch.Origin + " --> " + inputSearch.Destination;
                }

                return(View(result));
            }
            else
            {
                //Model state is not valid, for validation please check the model
                return(RedirectToAction("Index", "InvalidRequest"));
            }
        }
        public void SearchFlight()
        {
            SearchFlight search = new SearchFlight(driver);

            search.Search();
            string expected = "Flights from Mumbai to Bengaluru, and back";

            Assert.AreEqual(expected, search.SearchFlightValidation());
        }
Example #9
0
        public async Task <ActionResult <IEnumerable <Flight> > > GetFlights(SearchFlight search)
        {
            var flights = await searchFlightsRepo.GetFlights(_context, search);

            if (flights == null)
            {
                return(NotFound());
            }
            return(flights);
            //List<Flight> flights;
            //if (search.selectType == 1)
            //{
            //    return flights = await _context.Flights
            //        .Where(x => x.deleted == false && x.company == search.inputSearch)
            //        .Include(from => from.from)
            //        .Include(to => to.to)
            //        .Include(presedanje => presedanje.presedanje)
            //            .ThenInclude(gradoviPresedanja => gradoviPresedanja.gradoviPresedanja)
            //        .Include(aeroplane => aeroplane.aeroplane)
            //        .Include(allSeatsForThisFlight => allSeatsForThisFlight.allSeatsForThisFlight)
            //        .Include(luggage => luggage.luggage)
            //        .Include(ocene => ocene.ocene)
            //        .ToListAsync();
            //}
            //else if (search.selectType == 2)
            //{
            //    return flights = await _context.Flights
            //        .Where(x => x.deleted == false && x.from.city == search.inputSearch)
            //        .Include(from => from.from)
            //        .Include(to => to.to)
            //        .Include(presedanje => presedanje.presedanje)
            //            .ThenInclude(gradoviPresedanja => gradoviPresedanja.gradoviPresedanja)
            //        .Include(aeroplane => aeroplane.aeroplane)
            //        .Include(allSeatsForThisFlight => allSeatsForThisFlight.allSeatsForThisFlight)
            //        .Include(luggage => luggage.luggage)
            //        .Include(ocene => ocene.ocene)
            //        .ToListAsync();
            //}
            //else if (search.selectType == 3)
            //{
            //    return flights = await _context.Flights
            //        .Where(x => x.deleted == false && x.to.city == search.inputSearch)
            //        .Include(from => from.from)
            //        .Include(to => to.to)
            //        .Include(presedanje => presedanje.presedanje)
            //            .ThenInclude(gradoviPresedanja => gradoviPresedanja.gradoviPresedanja)
            //        .Include(aeroplane => aeroplane.aeroplane)
            //        .Include(allSeatsForThisFlight => allSeatsForThisFlight.allSeatsForThisFlight)
            //        .Include(luggage => luggage.luggage)
            //        .Include(ocene => ocene.ocene)
            //        .ToListAsync();
            //}


            //return BadRequest();
        }
Example #10
0
        public IActionResult Index()
        {
            HttpContext.Session.Remove("searchFlightTemp");
            var vm = new SearchFlight
            {
                DepartDate = DateTime.Today,
                ReturnDate = DateTime.Today
            };

            return(View(vm));
        }
Example #11
0
        public async Task <List <FlightDetails> > SearchFlightsAsync(SearchFlight bookingInfo)
        {
            string searchDetailsJson = JsonConvert.SerializeObject(bookingInfo);
            string response          = await this._serviceCallUtil.SearchFlightAsync(searchDetailsJson);

            if (!string.IsNullOrEmpty(response))
            {
                ParseResponseData(response);
            }
            return(this.FlightDetails);
        }
        public ActionResult Search(SearchFlight searchflight)
        {
            Flight flight = AutoMapper.Mapper.Map <SearchFlight, Flight>(searchflight);
            IEnumerable <Flight> flights      = flightBL.SearchDisplayFlight(flight);
            List <FlightModel>   flightModels = new List <FlightModel>();

            foreach (var temp in flights)
            {
                FlightModel flightModel = AutoMapper.Mapper.Map <Flight, FlightModel>(temp);       //Auto Mapper entity to model
                flightModels.Add(flightModel);
            }
            TempData["flightsDisplay"] = flightModels;
            return(View());
        }
        public IHttpActionResult GetFlights([FromBody] SearchFlight search)
        {
            var departureDate = search.departureDate.ToString("yyyyMMdd");
            var arrivalDate   = search.arrivalDate.ToString("yyyyMMdd");

            var url = $"http://developer.goibibo.com/api/search/?&app_id={appId}&app_key={appKey}&format=json&source={search.source}&destination={search.destination}&dateofdeparture={departureDate}&dateofarrival={arrivalDate}&seatingclass={search.seatingClass}&adults={search.numAdults}&children={search.numChildren}&infants={search.numInfants}&counter={search.counter}";

            var flights = GetDeserializedFlights(url);

            if (flights != null)
            {
                var results = flights.Data.OnwardFlights;
                results.AddRange(flights.Data.ReturnFlights);

                return(Ok(results));
            }

            return(BadRequest());
        }
        /*
         * THIS ACTION RESULT SEARCHES CORRESPONDING FLIGHT REQUESTED BY USER AND DISPLAYS FLIGHT DETAILS TO THE USER
         */
        public ActionResult BookFlight(SearchFlight search)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("SearchFlight", new { ErrMsg = "Please enter Source and Date of Journey. Destination is optional." }));
            }
            List <Flight> flights = new List <Flight>();
            string        sql     = "SELECT * FROM FLIGHT WHERE departure_airport LIKE '%" + search.Source
                                    + "%' AND arrival_airport LIKE '%" + search.Destination
                                    + "%' AND availability >= 1 AND departure_date = '" + search.DateOfJourney + "';";

            sql = String.Format(sql);
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                command = new SqlCommand(sql, connection);
                command.Connection.Open();
                var datareader = command.ExecuteReader();

                if (!datareader.HasRows)
                {
                    return(RedirectToAction("SearchFlight", new { ErrMsg = "No flights or seats available." }));
                }

                while (datareader.Read())
                {
                    flights.Add(new Flight()
                    {
                        FlightNo          = datareader.GetValue(7).ToString(),
                        PriceFirstClass   = (int)datareader.GetValue(1),
                        PriceEconomyClass = (int)datareader.GetValue(2),
                        DepartureAirport  = datareader.GetValue(3).ToString(),
                        ArrivalAirport    = datareader.GetValue(4).ToString(),
                        DepartureTime     = (DateTime)datareader.GetValue(5),
                        ArrivalTime       = (DateTime)datareader.GetValue(6),
                        DepartureDate     = (DateTime)datareader.GetValue(9),
                        Availability      = (int)datareader.GetValue(8)
                    });
                }
                connection.Close();
            }
            return(View(flights));
        }
Example #15
0
        public IHttpActionResult Search(FlightFilter filter)
        {
            try
            {
                var result = SearchFlight.GetFlights(filter);

                var respuesta = new
                {
                    errorCode    = 0,
                    messageError = "Consulta correcta.",
                    flights      = result
                };

                return(Ok(respuesta));
            }
            catch (Exception ex)
            {
                CatchError.Log4Net("ERROR", ex);
                return(BadRequest(ex.Message));
            }
        }
        public ActionResult ReceiveMsg2_1()
        {
            string        id     = Request.Params["fid"];
            TFlightTime   result = new SearchFlight().Search(id);
            List <string> list   = new List <string>();

            if (result.f_id != null)
            {
                list.Add(result.f_id);
                list.Add(result.t_airport);
                list.Add(result.ex_takeoff_time);
                list.Add(result.t_terminal);
                list.Add(result.l_airport);
                list.Add(result.ex_land_time);
                list.Add(result.l_termnal);
            }
            else
            {
                list.Add("-1");
            }
            return(View("ChangeFlight", list));
        }
Example #17
0
        public List <AdminViewFlight> searchFlight(SearchFlight search)
        {
            var db   = new WAPPContext();
            int from = db.Airport.Where(w => w.Name.Equals(search.From)).Select(s => s.ID).FirstOrDefault();
            int to   = db.Airport.Where(w => w.Name.Equals(search.To)).Select(s => s.ID).FirstOrDefault();
            List <AdminViewFlight> list = db.Flight.Where(w => w.Departure == from &&
                                                          w.Destination == to &&
                                                          w.TravelDate == search.Date).Select(e => new AdminViewFlight()
            {
                ID              = e.ID,
                TravelDate      = e.TravelDate,
                DepartureTime   = e.DepartureTime,
                Departure       = db.Airport.Where(w => w.Name.Equals(search.From)).Select(s => s.Name).FirstOrDefault(),
                DestinationTime = e.DestinationTime,
                Destination     = db.Airport.Where(w => w.Name.Equals(search.To)).Select(s => s.Name).FirstOrDefault(),
                ClassType       = e.ClassType,
                Seats           = e.Seats,
                Airplane        = db.Airplanes.Where(w => w.ID == e.Airplane.ID).Select(s => s.Name).FirstOrDefault(),
                Price           = e.Price
            }).ToList();

            return(list);
        }
        public IActionResult Index(SearchFlight flightBookInfo)
        {
            var result = this._flightBookRepo.SearchFlightsAsync(flightBookInfo).GetAwaiter().GetResult();

            return(View("SearchResults", result));
        }
Example #19
0
 public List <AdminViewFlight> searchFlight(SearchFlight search)
 {
     return(_repository.searchFlight(search));
 }
        public async Task <ActionResult <IEnumerable <Flight> > > GetFlights(MAANPP20ContextFlight _context, SearchFlight search)
        {
            List <Flight> flights;

            if (search.selectType == 1)
            {
                return(flights = await _context.Flights
                                 .Where(x => x.deleted == false && x.company == search.inputSearch)
                                 .Include(from => from.from)
                                 .Include(to => to.to)
                                 .Include(presedanje => presedanje.presedanje)
                                 .ThenInclude(gradoviPresedanja => gradoviPresedanja.gradoviPresedanja)
                                 .Include(aeroplane => aeroplane.aeroplane)
                                 .Include(allSeatsForThisFlight => allSeatsForThisFlight.allSeatsForThisFlight)
                                 .Include(luggage => luggage.luggage)
                                 .Include(ocene => ocene.ocene)
                                 .ToListAsync());
            }
            else if (search.selectType == 2)
            {
                return(flights = await _context.Flights
                                 .Where(x => x.deleted == false && x.from.city == search.inputSearch)
                                 .Include(from => from.from)
                                 .Include(to => to.to)
                                 .Include(presedanje => presedanje.presedanje)
                                 .ThenInclude(gradoviPresedanja => gradoviPresedanja.gradoviPresedanja)
                                 .Include(aeroplane => aeroplane.aeroplane)
                                 .Include(allSeatsForThisFlight => allSeatsForThisFlight.allSeatsForThisFlight)
                                 .Include(luggage => luggage.luggage)
                                 .Include(ocene => ocene.ocene)
                                 .ToListAsync());
            }
            else if (search.selectType == 3)
            {
                return(flights = await _context.Flights
                                 .Where(x => x.deleted == false && x.to.city == search.inputSearch)
                                 .Include(from => from.from)
                                 .Include(to => to.to)
                                 .Include(presedanje => presedanje.presedanje)
                                 .ThenInclude(gradoviPresedanja => gradoviPresedanja.gradoviPresedanja)
                                 .Include(aeroplane => aeroplane.aeroplane)
                                 .Include(allSeatsForThisFlight => allSeatsForThisFlight.allSeatsForThisFlight)
                                 .Include(luggage => luggage.luggage)
                                 .Include(ocene => ocene.ocene)
                                 .ToListAsync());
            }


            return(null);
        }
Example #21
0
 public ActionResult SearchChangeFlights(SearchFlight search)
 {
     return(PartialView("_ListChangeFlight", _AdminBll.searchFlight(search)));
 }
        public async Task <ActionResult <IEnumerable <FlightCompany> > > GetFlightCompany(MAANPP20ContextFlight _context, SearchFlight search)
        {
            List <FlightCompany> flightCompanies;

            if (search.selectType == 1)
            {
                return(flightCompanies = await _context.FlightCompanies
                                         .Where(x => x.deleted == false && x.name == search.inputSearch)
                                         .Include(address => address.address)
                                         .Include(destinations => destinations.destinations)
                                         .ThenInclude(startAddress => startAddress.startAddress)
                                         .Include(destinations => destinations.destinations)
                                         .ThenInclude(endAddress => endAddress.endAddress)
                                         .Include(admin => admin.admin)
                                         //.Include(flights => flights.flights)
                                         //.Include(ocene => ocene.ocene)

                                         /* izbacio sam sve ove parametre,
                                          *  jer nisu potrebni u prozoru koji
                                          *  poziva ovu metodu!*/
                                         .ToListAsync());
            }
            else if (search.selectType == 2)
            {
                return(flightCompanies = await _context.FlightCompanies
                                         .Where(x => x.deleted == false && x.address.city == search.inputSearch)
                                         .Include(address => address.address)
                                         .Include(destinations => destinations.destinations)
                                         .ThenInclude(startAddress => startAddress.startAddress)
                                         .Include(destinations => destinations.destinations)
                                         .ThenInclude(endAddress => endAddress.endAddress)
                                         .Include(admin => admin.admin)
                                         .ToListAsync());
            }
            else if (search.selectType == 3)
            {
                return(flightCompanies = await _context.FlightCompanies
                                         .Where(x => x.deleted == false && x.address.country == search.inputSearch)
                                         .Include(address => address.address)
                                         .Include(destinations => destinations.destinations)
                                         .ThenInclude(startAddress => startAddress.startAddress)
                                         .Include(destinations => destinations.destinations)
                                         .ThenInclude(endAddress => endAddress.endAddress)
                                         .Include(admin => admin.admin)
                                         .ToListAsync());
            }


            return(null);
        }
Example #23
0
        public IActionResult GetFlights([FromBody] SearchFlight searchFlightCriteria)
        {
            Logger?.LogDebug("'{0}' has been invoked", nameof(GetFlights));

            if (!searchFlightCriteria.NumberOfRecord.HasValue)
            {
                searchFlightCriteria.NumberOfRecord = 20;
            }

            var response = new ListResponse <Flight>();

            try
            {
                if (searchFlightCriteria.GetType()
                    .GetProperties()
                    .Select(p => p.GetValue(searchFlightCriteria))
                    .Any(p => p != null)
                    )
                {
                    var flightDetail = DbContext.Flight.Where(p =>
                                                              (string.IsNullOrEmpty(searchFlightCriteria.From) || p.Depart == searchFlightCriteria.From) &&
                                                              (string.IsNullOrEmpty(searchFlightCriteria.To) || p.Return == searchFlightCriteria.To) &&
                                                              (searchFlightCriteria.DepartDate == null ||
                                                               // p.DepartTime.ToDateTime() == searchFlightCriteria.DepartDate.Value.Date) &&
                                                               //(searchFlightCriteria.ReturnDate == null ||
                                                               // p.ReturnTime.ToDateTime() == searchFlightCriteria.ReturnDate.Value.Date) &&
                                                               //(string.IsNullOrEmpty(searchFlightCriteria.ClassType) ||
                                                               // p.ClassType.Contains(searchFlightCriteria.ClassType)) &&
                                                               (searchFlightCriteria.RoundTrip == null || p.RoundTrip == searchFlightCriteria.RoundTrip) &&
                                                               (searchFlightCriteria.PriceFrom == null || p.TotalMoney >= searchFlightCriteria.PriceFrom) &&
                                                               (searchFlightCriteria.PriceTo == null || p.TotalMoney <= searchFlightCriteria.PriceTo) &&
                                                               (searchFlightCriteria.Airlines == null || searchFlightCriteria.Airlines.Count == 0 ||
                                                                searchFlightCriteria.Airlines.Contains(p.DepartAirlineName) ||
                                                                searchFlightCriteria.Airlines.Contains(p.ReturnAirlineName))));


                    if (searchFlightCriteria.OrderBy == OrderByEnum.TotalMoney)
                    {
                        flightDetail = flightDetail.OrderBy(p => p.TotalMoney);
                    }

                    if (searchFlightCriteria.OrderBy == OrderByEnum.DepartTime)
                    {
                        flightDetail = flightDetail.OrderBy(p => Convert.ToDateTime(p.DepartTime));
                    }


                    response.Model = flightDetail.Take(searchFlightCriteria.NumberOfRecord.Value).ToList();
                }
                else
                {
                    response.Model = DbContext.Flight.ToList();
                }
            }
            catch (Exception ex)
            {
                response.DidError     = true;
                response.ErrorMessage = ex.InnerException != null ? ex.InnerException.Message : ex.Message;

                Logger?.LogCritical("There was an error on '{0}' invocation: {1}", nameof(GetFlights), ex);
            }

            return(response.ToHttpResponse());
        }
Example #24
0
        public async Task <ActionResult> GetFlightsAsync(Pagination pagination, SearchFlight search)
        {
            // Mapping: Flight
            var flightsSource = await _unitOfWork.Flights.GetAllAsync();

            await _unitOfWork.Airlines.GetAllAsync();

            await _unitOfWork.Airports.GetAllAsync();

            await _unitOfWork.TicketCategories.GetAllAsync();

            await _unitOfWork.Flights.GetFlightTicketCategoriesAsync();

            var flights = _mapper.Map <IEnumerable <Flight>, IEnumerable <FlightDTO> >(flightsSource);

            // Search by Id:
            if (search.Id != "")
            {
                flights = flights.Where(f =>
                                        f.Id.ToLower().Contains(search.Id.ToLower()));
            }

            // Search by StartTime:
            if (search.StartTime != null)
            {
                flights = flights.Where(f =>
                                        f.StartTime == search.StartTime);
            }

            /// Search by FlightTime:
            if (search.FlightTime != null)
            {
                flights = flights.Where(f =>
                                        f.FlightTime == search.FlightTime);
            }

            // Search by AirportFrom:
            if (search.AirportFrom != "")
            {
                flights = flights.Where(f =>
                                        f.AirportFrom.ToLower().Contains(search.AirportFrom.ToLower()));
            }

            // Search by AirportTo:
            if (search.AirportTo != "")
            {
                flights = flights.Where(f =>
                                        f.AirportTo.ToLower().Contains(search.AirportTo.ToLower()));
            }

            // Search by AirlineName:
            if (search.AirlineName != "")
            {
                var airlines = await _unitOfWork.Airlines.GetAllAsync();

                flights = (from f in flights
                           from a in airlines
                           where f.AirlineId.Equals(a.Id) &&
                           a.Name.ToLower().Contains(search.AirlineName.ToLower())
                           select f);
            }

            // Search by Status:
            if (search.Status != null)
            {
                flights = flights.Where(f =>
                                        f.Status == search.Status);
            }

            // Sort Asc:
            if (search.sortAsc != "")
            {
                flights = flights.OrderBy(f =>
                                          f.GetType().GetProperty(search.sortAsc).GetValue(f));
            }

            // Sort Desc:
            if (search.sortDesc != "")
            {
                flights = flights.OrderByDescending(f =>
                                                    f.GetType().GetProperty(search.sortDesc).GetValue(f));
            }

            return(Ok(PaginatedList <FlightDTO> .Create(flights, pagination.current, pagination.pageSize)));
        }
Example #25
0
        public async Task <ActionResult> GetFlightsAsync([FromQuery] Pagination pagination, [FromQuery] SearchFlight search)
        {
            var flights = await _service.GetFlightsAsync(pagination, search);

            return(flights);
        }
Example #26
0
        public async Task <ActionResult <IEnumerable <FlightCompany> > > GetFlightCompany(SearchFlight search)
        {
            var flightCompanies = await searchFlightsRepo.GetFlightCompany(_context, search);

            if (flightCompanies == null)
            {
                return(NotFound());
            }
            return(flightCompanies);
            //List<FlightCompany> flightCompanies;
            //if (search.selectType == 1)
            //{
            //    return flightCompanies = await _context.FlightCompanies
            //        .Where(x => x.deleted == false && x.name == search.inputSearch)
            //        .Include(address => address.address)
            //        .Include(destinations => destinations.destinations)
            //            .ThenInclude(startAddress => startAddress.startAddress)
            //        .Include(destinations => destinations.destinations)
            //            .ThenInclude(endAddress => endAddress.endAddress)
            //        .Include(admin => admin.admin)
            //        //.Include(flights => flights.flights)
            //        //.Include(ocene => ocene.ocene)
            //        /* izbacio sam sve ove parametre,
            //            jer nisu potrebni u prozoru koji
            //            poziva ovu metodu!*/
            //        .ToListAsync();
            //}
            //else if (search.selectType == 2)
            //{
            //    return flightCompanies = await _context.FlightCompanies
            //        .Where(x => x.deleted == false && x.address.city == search.inputSearch)
            //        .Include(address => address.address)
            //        .Include(destinations => destinations.destinations)
            //            .ThenInclude(startAddress => startAddress.startAddress)
            //        .Include(destinations => destinations.destinations)
            //            .ThenInclude(endAddress => endAddress.endAddress)
            //        .Include(admin => admin.admin)
            //        .ToListAsync();
            //}
            //else if (search.selectType == 3)
            //{
            //   return flightCompanies = await _context.FlightCompanies
            //        .Where(x => x.deleted == false && x.address.country == search.inputSearch)
            //        .Include(address => address.address)
            //        .Include(destinations => destinations.destinations)
            //            .ThenInclude(startAddress => startAddress.startAddress)
            //        .Include(destinations => destinations.destinations)
            //            .ThenInclude(endAddress => endAddress.endAddress)
            //        .Include(admin => admin.admin)
            //        .ToListAsync();
            //}


            //return BadRequest();
        }