From 14c0e506a44085af0789d8cc9a3a1e0218233bf3 Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Fri, 12 Jun 2020 04:06:56 +0200 Subject: [PATCH] fix trips without legs --- bahnplan.web/Pages/Index.cshtml | 6 ++++++ 1 file changed, 6 insertions(+) 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);