Skip to content

Commit

Permalink
Fix for #110 - der skal kun være uddannelsesflyvninger (mindst 1 grad…
Browse files Browse the repository at this point in the history
…ing) på listen
  • Loading branch information
plaursen authored and janhebnes committed Apr 7, 2021
1 parent cfbd02c commit c68e923
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions FlightJournal.Web/Controllers/TrainingLogHistoryController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,15 @@ public ActionResult ExportToJson(DateTime? fromDate, DateTime? toDate)
private IEnumerable<Flight> SelectFlights(DateTime fromDate, DateTime toDate)
{
IEnumerable<Flight> flights;
var flightIds = db.AppliedExercises.Select(x => x.FlightId).Union(db.TrainingFlightAnnotations.Select(y => y.FlightId)).Distinct().ToList();
var trainingFlightIds = db.AppliedExercises
.Where(x=>x.Grading != null)
.Select(x => x.FlightId)
.Distinct().ToList();

switch (UsersAccessScope())
{
case AccessScope.AllFlights:
flights = db.Flights.Where(x => x.Date >= fromDate && x.Date <= toDate && flightIds.Contains(x.FlightId));
flights = db.Flights.Where(x => x.Date >= fromDate && x.Date <= toDate && trainingFlightIds.Contains(x.FlightId));
if (ClubController.CurrentClub.ShortName != null)
{
flights = flights.Where(f =>
Expand All @@ -172,7 +175,7 @@ private IEnumerable<Flight> SelectFlights(DateTime fromDate, DateTime toDate)
break;
case AccessScope.OwnFlights:
var pilotId = Request.Pilot().PilotId;
flights = db.Flights.Where(x => x.Date >= fromDate && x.Date <= toDate && flightIds.Contains(x.FlightId) && (x.PilotId == pilotId || x.PilotBackseatId == pilotId));
flights = db.Flights.Where(x => x.Date >= fromDate && x.Date <= toDate && trainingFlightIds.Contains(x.FlightId) && (x.PilotId == pilotId || x.PilotBackseatId == pilotId));
break;
default:
flights = Enumerable.Empty<Flight>();
Expand Down

0 comments on commit c68e923

Please sign in to comment.