2020-06-11 20:29:16 +02:00
|
|
|
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 {
|
2020-10-19 00:30:10 +02:00
|
|
|
public List<Leg> Legs;
|
|
|
|
public bool RedirToIndex;
|
2020-10-19 01:36:44 +02:00
|
|
|
public new string User;
|
2020-06-11 20:29:16 +02:00
|
|
|
|
|
|
|
public void OnGet() {
|
2020-06-12 00:37:55 +02:00
|
|
|
if (HttpContext.Session.GetString("authorized") != "true")
|
2020-06-11 20:29:16 +02:00
|
|
|
return;
|
2020-06-11 22:25:37 +02:00
|
|
|
|
2020-06-11 20:29:16 +02:00
|
|
|
using var db = new Database.DbConn();
|
|
|
|
if (Request.Query.ContainsKey("separator")) {
|
|
|
|
var leg = db.Legs.First(p => p.LegId == int.Parse(Request.Query["legid"]));
|
2020-06-12 02:21:59 +02:00
|
|
|
if (leg.UserId != int.Parse(HttpContext.Session.GetString("uid")))
|
|
|
|
return;
|
|
|
|
|
2020-06-11 20:29:16 +02:00
|
|
|
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,
|
2020-06-12 00:37:55 +02:00
|
|
|
DepTime = leg.DepTime + "_placeholder"
|
2020-06-11 20:29:16 +02:00
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-19 01:55:36 +02:00
|
|
|
Legs = db.Legs.Where(p => p.TripId == int.Parse(Request.Query["id"])).OrderBy(p => p.DepTime).ToList();
|
|
|
|
|
2020-10-19 01:54:14 +02:00
|
|
|
if (!db.Legs.Any(p => p.TripId == int.Parse(Request.Query["id"]))) {
|
2020-06-13 07:30:56 +02:00
|
|
|
RedirToIndex = true;
|
2020-10-19 01:54:14 +02:00
|
|
|
return;
|
|
|
|
}
|
2020-06-13 07:30:56 +02:00
|
|
|
|
2020-10-19 00:30:10 +02:00
|
|
|
User = db.Users.First(p => p.UserId == Legs.First().UserId).Username;
|
2020-06-11 20:29:16 +02:00
|
|
|
}
|
2020-06-12 05:29:41 +02:00
|
|
|
|
|
|
|
public void OnPost() {
|
|
|
|
if (HttpContext.Session.GetString("authorized") != "true")
|
|
|
|
return;
|
|
|
|
|
|
|
|
using var db = new Database.DbConn();
|
|
|
|
if (!Request.Form.ContainsKey("comment"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
var leg = db.Legs.First(p => p.LegId == int.Parse(Request.Form["id"]));
|
|
|
|
if (leg.UserId != int.Parse(HttpContext.Session.GetString("uid")))
|
|
|
|
return;
|
|
|
|
|
|
|
|
leg.Comment = Request.Form["comment"];
|
|
|
|
|
|
|
|
db.Update(leg);
|
|
|
|
}
|
2020-06-11 20:29:16 +02:00
|
|
|
}
|
|
|
|
}
|