98 lines
4.5 KiB
Plaintext
98 lines
4.5 KiB
Plaintext
@page
|
|
@using Microsoft.AspNetCore.Http
|
|
@using Microsoft.AspNetCore.Http.Extensions
|
|
@using LinqToDB
|
|
@using bahnplan.web.database
|
|
@model IndexModel
|
|
@{
|
|
ViewData["Title"] = "Home";
|
|
}
|
|
|
|
<div class="text-center">
|
|
@if (HttpContext.Session.GetString("authorized") != "true") {
|
|
<h1 class="display-4">Welcome</h1>
|
|
<p>Please log in to see your personal plan.</p>
|
|
}
|
|
else {
|
|
<h1 class="display-4">
|
|
Welcome, @Model.AuthorizedUser.Username
|
|
</h1>
|
|
<p>
|
|
Here are your planned trips.
|
|
</p>
|
|
<table class="table table-striped">
|
|
<thead>
|
|
<tr>
|
|
<th scope="col">Date</th>
|
|
<th scope="col">Origin</th>
|
|
<th scope="col">Via</th>
|
|
<th scope="col">Destination</th>
|
|
<th scope="col">Comments</th>
|
|
<th scope="col">Actions</th>
|
|
<th scope="col">Danger zone</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
@{
|
|
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) + "<br/>" + legs.Last().DepTime.Substring(0, 10);
|
|
<tr>
|
|
<td>@Html.Raw(dates)</td>
|
|
<td>@Html.Raw(legs.First().DepStation.PadRight(30, ' ').Substring(0, 30).TrimEnd())</td>
|
|
<td>
|
|
@((from index in from leg in legs where leg.TrainType == "placeholder" select legs.IndexOf(leg) select legs[index - 1].ArrStation).ToList().DefaultIfEmpty("-").Aggregate((s1, s2) => $"{s1}, {s2}"))
|
|
</td>
|
|
<td>@Html.Raw(legs.Last().ArrStation.PadRight(30, ' ').Substring(0, 30).TrimEnd())</td>
|
|
<td>
|
|
@Html.Raw(legs.Where(leg => !string.IsNullOrWhiteSpace(leg.Comment)).Select(p => p.Comment).DefaultIfEmpty("").Aggregate((s1, s2) => $"{s1}<br/>{s2}"))
|
|
</td>
|
|
<td>
|
|
<a class="btn btn-sm btn-primary" href="/Trip?id=@trip.TripId">View</a>
|
|
</td>
|
|
<td>
|
|
<a class="btn btn-sm btn-outline-danger" href="/Delete?item=trip&id=@trip.TripId&redir=@Request.GetDisplayUrl().UrlEncode()">Delete Trip</a>
|
|
</td>
|
|
</tr>
|
|
}
|
|
}
|
|
</tbody>
|
|
</table>
|
|
<br/>
|
|
<div class="d-flex flex-row" style="justify-content: space-between">
|
|
<div class="d-flex p-2" style="width: 40%">
|
|
<form style="width: 100%" method="GET" action="/Ticket">
|
|
<h3>Add trip from ticket</h3>
|
|
<br/>
|
|
<div class="form-group">
|
|
<input type="text" class="form-control" name="order" placeholder="bahn.de order #">
|
|
</div>
|
|
<div class="form-group">
|
|
<input type="text" class="form-control" name="name" placeholder="Last name of traveller">
|
|
</div>
|
|
<br/>
|
|
<button type="submit" class="btn btn-primary">Submit</button>
|
|
</form>
|
|
</div>
|
|
<div class="d-flex p-2" style="width: 40%">
|
|
<form style="width: 100%" method="GET" action="/OEAPI">
|
|
<h3>Add trip from oeffisear.ch</h3>
|
|
<br/>
|
|
<div class="form-group">
|
|
<input type="text" class="form-control" name="link" placeholder="oeffisear.ch link / shortcode">
|
|
</div>
|
|
<br/>
|
|
<button type="submit" class="btn btn-primary">Submit</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
}
|
|
</div> |