diff --git a/bahnplan.web/Pages/SharedTrip.cshtml b/bahnplan.web/Pages/SharedTrip.cshtml new file mode 100644 index 0000000..702432d --- /dev/null +++ b/bahnplan.web/Pages/SharedTrip.cshtml @@ -0,0 +1,79 @@ +@page +@using Microsoft.AspNetCore.Http +@using Microsoft.AspNetCore.Http.Extensions +@model SharedTripModel +@{ + ViewData["Title"] = "Shared Trip"; + + if (Model.RedirToIndex) { + Response.Redirect("/"); + return; + } + + if (!Model.Legs.Any()) { + Response.Redirect("/"); + return; + } + + var dep = Model.Legs.First().DepStation; + var arr = Model.Legs.Last().ArrStation; +} + +
+

+ @Model.User's Trip from @dep to @arr, starting @DateTime.Parse(Model.Legs.First().DepTime).ToString("yyyy-MM-dd HH:mm") +

+
+
+ + + + + + + + + + + + + @foreach (var leg in Model.Legs) { + if (leg.TrainType == "placeholder") { + + + + + + + continue; + } + var deptime = DateTime.Parse(leg.DepTime); + var arrtime = DateTime.Parse(leg.ArrTime); + var date = DateTime.Parse(leg.DepTime).ToString("ddd, dd.MM."); + var dept = deptime.ToString("HH:mm"); + var arrt = arrtime.ToString("HH:mm"); + + + + + + + + + } + +
DateDepartureArrivalTrainCommentActions
+ @date + + @dept @Html.Raw(leg.DepStation.PadRight(30, ' ').Substring(0, 30).TrimEnd()) + + @arrt @Html.Raw(leg.ArrStation.PadRight(30, ' ').Substring(0, 30).TrimEnd()) + @leg.TrainType @leg.TrainNr + @if (!string.IsNullOrWhiteSpace(leg.Comment)) { + @Html.Raw(leg.Comment) + } + + Marudor + Travelynx +
+
\ No newline at end of file diff --git a/bahnplan.web/Pages/SharedTrip.cshtml.cs b/bahnplan.web/Pages/SharedTrip.cshtml.cs new file mode 100644 index 0000000..4b97cce --- /dev/null +++ b/bahnplan.web/Pages/SharedTrip.cshtml.cs @@ -0,0 +1,25 @@ +using System.Collections.Generic; +using System.Linq; +using bahnplan.web.database; +using bahnplan.web.database.Tables; +using Microsoft.AspNetCore.Mvc.RazorPages; + +namespace bahnplan.web.Pages { + public class SharedTripModel : PageModel { + public new string User; + public List Legs; + public bool RedirToIndex; + + public void OnGet() { + using var db = new Database.DbConn(); + + if (!db.Legs.Any(p => p.TripId == int.Parse(Request.Query["id"]))) + RedirToIndex = true; + + Legs = db.Legs.Where(p => p.TripId == int.Parse(Request.Query["id"])).OrderBy(p => p.DepTime).ToList(); + User = db.Users.First(p => p.UserId == Legs.First().UserId).Username; + if (Request.Query["user"] != User) + RedirToIndex = true; + } + } +} \ No newline at end of file diff --git a/bahnplan.web/Pages/Trip.cshtml b/bahnplan.web/Pages/Trip.cshtml index 16f2381..189c954 100644 --- a/bahnplan.web/Pages/Trip.cshtml +++ b/bahnplan.web/Pages/Trip.cshtml @@ -35,8 +35,6 @@ var dep = Model.Legs.First().DepStation; var arr = Model.Legs.Last().ArrStation; - var deplenmax = Model.Legs.Max(p => p.DepStation.Length) + 1; - var arrlenmax = Model.Legs.Max(p => p.ArrStation.Length) + 1; }
@@ -145,6 +143,7 @@
@if (!Request.Query.ContainsKey("edit")) { + Share Trip Edit Trip } else { diff --git a/bahnplan.web/Pages/Trip.cshtml.cs b/bahnplan.web/Pages/Trip.cshtml.cs index fd44eeb..a6e6cfd 100644 --- a/bahnplan.web/Pages/Trip.cshtml.cs +++ b/bahnplan.web/Pages/Trip.cshtml.cs @@ -8,8 +8,9 @@ using Microsoft.AspNetCore.Mvc.RazorPages; namespace bahnplan.web.Pages { public class TripModel : PageModel { - public List Legs; - public bool RedirToIndex; + public new string User; + public List Legs; + public bool RedirToIndex; public void OnGet() { if (HttpContext.Session.GetString("authorized") != "true") @@ -40,6 +41,7 @@ namespace bahnplan.web.Pages { RedirToIndex = true; Legs = db.Legs.Where(p => p.TripId == int.Parse(Request.Query["id"])).OrderBy(p => p.DepTime).ToList(); + User = db.Users.First(p => p.UserId == Legs.First().UserId).Username; } public void OnPost() {