This repository has been archived on 2023-04-02. You can view files and clone it, but cannot push or open issues or pull requests.
trainav/bahnplan.web/Pages/Index.cshtml
2020-06-12 18:19:28 +02:00

88 lines
3.9 KiB
Plaintext

@page
@using Microsoft.AspNetCore.Http
@using bahnplan.web.database
@using System.Linq
@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">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.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).Replace(" ", "&nbsp;"))</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).Replace(" ", "&nbsp;"))</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">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>