public async Task <AllFlightsDto> GetSelectedFlightAdminAsync(Guid FlightId) { FlightsDto flightsDto = await GetSelectedFlightPilotAsync(FlightId); var selectedFlight = await _appDbContext.Flight .Include(e => e.User) .FirstOrDefaultAsync(f => f.FlightId == FlightId); return(new AllFlightsDto() { FlightId = flightsDto.FlightId, FlightDate = flightsDto.FlightDate, FlightTime = flightsDto.FlightTime, Status = flightsDto.Status, TakeoffPlace = flightsDto.TakeoffPlace, LandPlace = flightsDto.LandPlace, PilotName = selectedFlight.User.UserName, Email = selectedFlight.User.Email }); }
private async Task <List <FlightsDto> > GetFlightsAsync(Guid?UserId = null, int?status = null) { List <FlightsDto> Flights = new List <FlightsDto>(); var queryFlights = from f in _appDbContext.Flight select f; List <Flight> flights = new List <Flight>(); if (UserId != null) { flights = await queryFlights.Where(f => f.UserId == UserId) .Include(e => e.TakeoffPlace) .Include(e => e.LandPlace) .ToListAsync(); } if (status != null) { switch (status) { case 0: flights = await queryFlights.Where(f => f.Status == Status.Accepted) /// Úgy kevesebbet kell copyzni, ha először csinálsz egy query-t, hívsz rá include-okat /// és a swuitch-be csak a where feltételt hívod rá... /// query = query.Where(f => f.Status == Status.Accepted) pl .Include(e => e.User) .Include(e => e.TakeoffPlace) .Include(e => e.LandPlace) .ToListAsync(); break; case 1: flights = await queryFlights.Where(f => f.Status == Status.Denied) .Include(e => e.User) .Include(e => e.TakeoffPlace) .Include(e => e.LandPlace) .ToListAsync(); break; case 2: flights = await queryFlights.Where(f => f.Status == Status.Waiting_For_Accept) .Include(e => e.User) .Include(e => e.TakeoffPlace) .Include(e => e.LandPlace) .ToListAsync(); break; default: flights = await queryFlights.Where(f => f.Status == Status.Waiting_For_Accept) .Include(e => e.User) .Include(e => e.TakeoffPlace) .Include(e => e.LandPlace) .ToListAsync(); break; } } List <Airport> airports = await _appDbContext.Airport .Include(e => e.GlobalPoint) .ToListAsync(); string DepPlace = ""; string ArrPlace = ""; foreach (var flight in flights) { DepPlace = airports.Find(m => CalculateDistance(m.GlobalPoint, flight.TakeoffPlace) <= 3000.0).AirportName; if (airports.Find(m => CalculateDistance(m.GlobalPoint, flight.LandPlace) <= 3000.0) == null) { ArrPlace = "Terep"; } else { ArrPlace = airports.Find(m => CalculateDistance(m.GlobalPoint, flight.LandPlace) <= 3000.0).AirportName; } FlightsDto flightDto; if (status != null) { flightDto = new AllFlightsDto(); (flightDto as AllFlightsDto).PilotName = flight.User.UserName; (flightDto as AllFlightsDto).Email = flight.User.Email; } else { flightDto = new FlightsDto(); } /// Ezeknek a lespórolására jó az Automapper - Mapper.Map<FlightsDto>(flight) /// Azt is ajánlom kipróbálni majd flightDto.FlightId = flight.FlightId; flightDto.FlightDate = flight.FlightDate; flightDto.TakeoffPlace = DepPlace; flightDto.LandPlace = ArrPlace; flightDto.FlightTime = flight.FlightTime; flightDto.Status = flight.Status; Flights.Add(flightDto); } return(Flights); }