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/trainav.web/Pages/Trip.cshtml.cs

67 lines
1.8 KiB
C#
Raw Normal View History

2020-06-11 20:29:16 +02:00
using System.Collections.Generic;
using System.Linq;
using LinqToDB;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.RazorPages;
2022-04-29 14:59:24 +02:00
using trainav.web.database;
using trainav.web.database.Tables;
2020-06-11 20:29:16 +02:00
2022-04-29 14:59:24 +02:00
namespace trainav.web.Pages {
2020-06-11 20:29:16 +02:00
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() {
if (HttpContext.Session.GetString("authorized") != "true")
2020-06-11 20:29:16 +02:00
return;
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"]));
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,
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
}
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
}
}