diff --git a/bahnplan.web/Pages/Index.cshtml b/bahnplan.web/Pages/Index.cshtml index 4ecef1c..e58e26e 100644 --- a/bahnplan.web/Pages/Index.cshtml +++ b/bahnplan.web/Pages/Index.cshtml @@ -2,6 +2,7 @@ @using Microsoft.AspNetCore.Http @using Microsoft.AspNetCore.Http.Extensions @using bahnplan.web.database +@using LinqToDB @model IndexModel @{ ViewData["Title"] = "Home"; @@ -35,6 +36,11 @@ await using var db = new Database.DbConn(); var trips = db.Trips.Where(p => p.UserId == Model.AuthorizedUser.UserId).ToList(); + foreach (var trip in trips.Where(trip => !db.Legs.Any(p => p.TripId == trip.TripId))) { + await db.DeleteAsync(trip); + trips = db.Trips.Where(p => p.UserId == Model.AuthorizedUser.UserId).ToList(); + } + foreach (var trip in trips.OrderBy(p => db.Legs.First(a => a.TripId == p.TripId).ArrTime)) { var legs = db.Legs.Where(p => p.TripId == trip.TripId).OrderBy(p => p.DepTime).ToList(); var dates = DateTime.Parse(legs.First().DepTime).Date == DateTime.Parse(legs.Last().DepTime).Date ? legs.First().DepTime.Substring(0, 10) : legs.First().DepTime.Substring(0, 10) + "
" + legs.Last().DepTime.Substring(0, 10);