add share function
This commit is contained in:
parent
a15aceb114
commit
c1fe9d327f
79
bahnplan.web/Pages/SharedTrip.cshtml
Normal file
79
bahnplan.web/Pages/SharedTrip.cshtml
Normal file
|
@ -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;
|
||||
}
|
||||
|
||||
<div>
|
||||
<p>
|
||||
@Model.User's Trip from <b>@dep</b> to <b>@arr</b>, starting @DateTime.Parse(Model.Legs.First().DepTime).ToString("yyyy-MM-dd HH:mm")
|
||||
</p>
|
||||
</div>
|
||||
<div>
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">Date</th>
|
||||
<th scope="col">Departure</th>
|
||||
<th scope="col">Arrival</th>
|
||||
<th scope="col">Train</th>
|
||||
<th scope="col">Comment</th>
|
||||
<th scope="col">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var leg in Model.Legs) {
|
||||
if (leg.TrainType == "placeholder") {
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
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");
|
||||
<tr>
|
||||
<td>
|
||||
@date
|
||||
</td>
|
||||
<td>
|
||||
<b>@dept</b> @Html.Raw(leg.DepStation.PadRight(30, ' ').Substring(0, 30).TrimEnd())
|
||||
</td>
|
||||
<td>
|
||||
<b>@arrt</b> @Html.Raw(leg.ArrStation.PadRight(30, ' ').Substring(0, 30).TrimEnd())
|
||||
</td>
|
||||
<td>@leg.TrainType @leg.TrainNr</td>
|
||||
<td>
|
||||
@if (!string.IsNullOrWhiteSpace(leg.Comment)) {
|
||||
@Html.Raw(leg.Comment)
|
||||
}
|
||||
</td>
|
||||
<td>
|
||||
<a class="btn btn-sm btn-primary" href="https://marudor.de/details/@leg.TrainType @leg.TrainNr/@(deptime.ToUniversalTime().Subtract(new DateTime(1970, 1, 1)).TotalSeconds)000/?station=@leg.DepStationId" target="_blank">Marudor</a>
|
||||
<a class="btn btn-sm btn-warning" href="https://travelynx.de/s/@leg.DepStationId?train=@leg.TrainType @leg.TrainNr" target="_blank">Travelynx</a>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
25
bahnplan.web/Pages/SharedTrip.cshtml.cs
Normal file
25
bahnplan.web/Pages/SharedTrip.cshtml.cs
Normal file
|
@ -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<Leg> 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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
<div>
|
||||
|
@ -145,6 +143,7 @@
|
|||
</div>
|
||||
|
||||
@if (!Request.Query.ContainsKey("edit")) {
|
||||
<a class="btn btn-sm btn-success" href="/SharedTrip?id=@Request.Query["id"]&user=@Model.User">Share Trip</a>
|
||||
<a class="btn btn-sm btn-secondary" href="/Trip?id=@Request.Query["id"]&edit=true">Edit Trip</a>
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -8,8 +8,9 @@ using Microsoft.AspNetCore.Mvc.RazorPages;
|
|||
|
||||
namespace bahnplan.web.Pages {
|
||||
public class TripModel : PageModel {
|
||||
public List<Leg> Legs;
|
||||
public bool RedirToIndex;
|
||||
public new string User;
|
||||
public List<Leg> 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() {
|
||||
|
|
Reference in a new issue