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/SharedTrip.cshtml.cs

27 lines
744 B
C#
Raw Permalink Normal View History

2020-10-19 00:30:10 +02:00
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Mvc.RazorPages;
2022-04-29 14:59:24 +02:00
using trainav.web.database;
using trainav.web.database.Tables;
2020-10-19 00:30:10 +02:00
2022-05-03 00:20:02 +02:00
namespace trainav.web.Pages;
2020-10-19 00:30:10 +02:00
2022-05-03 00:20:02 +02:00
public class SharedTripModel : PageModel {
public List<Leg> Legs;
public bool RedirToIndex;
public new string User;
2020-10-19 00:30:10 +02:00
2022-05-03 00:20:02 +02:00
public void OnGet() {
using var db = new Database.DbConn();
2020-10-19 00:30:10 +02:00
2022-05-03 00:20:02 +02:00
if (!db.Legs.Any(p => p.TripId == int.Parse(Request.Query["id"]))) {
RedirToIndex = true;
return;
2020-10-19 00:30:10 +02:00
}
2022-05-03 00:20:02 +02:00
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;
2020-10-19 00:30:10 +02:00
}
}