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#

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