49 lines
1.3 KiB
C#
49 lines
1.3 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using bahnplan.web.database;
|
|
using bahnplan.web.database.Tables;
|
|
using LinqToDB;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
|
|
namespace bahnplan.web.Pages {
|
|
public class TripModel : PageModel {
|
|
public List<Leg> Legs;
|
|
public Ticket Ticket;
|
|
|
|
public void OnGet() {
|
|
|
|
if (HttpContext.Session.GetString("authorized") != "true") {
|
|
return;
|
|
}
|
|
|
|
using var db = new Database.DbConn();
|
|
if (Request.Query.ContainsKey("separator")) {
|
|
var leg = db.Legs.First(p => p.LegId == int.Parse(Request.Query["legid"]));
|
|
db.Insert(new Leg {
|
|
TripId = int.Parse(Request.Query["id"]),
|
|
UserId = int.Parse(HttpContext.Session.GetString("uid")),
|
|
TrainType = "placeholder",
|
|
TrainNr = int.Parse(Request.Query["legid"]),
|
|
ArrStation = "_",
|
|
ArrStationId = 0,
|
|
ArrTime = "_",
|
|
DepStation = "_",
|
|
DepStationId = 0,
|
|
DepTime = leg.DepTime + "_placeholder",
|
|
});
|
|
return;
|
|
}
|
|
|
|
var legs = db.Legs.Where(p => p.TripId == int.Parse(Request.Query["id"])).ToList();
|
|
Legs = new List<Leg>();
|
|
foreach (var j in legs) {
|
|
Legs.Add(j);
|
|
if (j.TicketId != 0)
|
|
Ticket = db.Tickets.First(p => p.TicketId == j.TicketId);
|
|
}
|
|
|
|
Legs = Legs.OrderBy(p => p.DepTime).ToList();
|
|
}
|
|
}
|
|
} |