display card/qr expiry & refresh; refactor Cards page; code cleanup

This commit is contained in:
Laura Hausmann 2020-06-12 00:37:55 +02:00
parent 484d853f46
commit 5eacd5a7ec
Signed by: zotan
GPG key ID: 5EC1D38FFC321311
42 changed files with 859 additions and 611 deletions

View file

@ -1,29 +1,21 @@
using System; using System.Diagnostics.CodeAnalysis;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
namespace bahnplan.web.Controllers { namespace bahnplan.web.Controllers {
[ApiController] [ApiController, Route("api/[controller]")]
[Route("api/[controller]")]
public class TestController : ControllerBase { public class TestController : ControllerBase {
[HttpGet] [HttpGet]
public ApiResponse Get() { public ApiResponse Get() => new ApiResponse("test", 4);
return new ApiResponse("test", 4);
}
} }
[SuppressMessage("ReSharper", "UnusedAutoPropertyAccessor.Global")] [SuppressMessage("ReSharper", "UnusedAutoPropertyAccessor.Global")]
public class ApiResponse { public class ApiResponse {
public string String1 { get; }
public int Int1 { get; }
public ApiResponse(string string1, int int1) { public ApiResponse(string string1, int int1) {
String1 = string1; String1 = string1;
Int1 = int1; Int1 = int1;
} }
public string String1 { get; }
public int Int1 { get; }
} }
} }

View file

@ -11,136 +11,204 @@ using System.Globalization;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Converters; using Newtonsoft.Json.Converters;
namespace bahnplan.web.JSON.CardResponse namespace bahnplan.web.JSON.CardResponse {
{ public partial class CardResponse {
public partial class CardResponse [JsonProperty("?xml", NullValueHandling = NullValueHandling.Ignore)]
{ public Xml Xml { get; set; }
[JsonProperty("?xml", NullValueHandling = NullValueHandling.Ignore)] public Xml Xml { get; set; }
[JsonProperty("rporderdetails", NullValueHandling = NullValueHandling.Ignore)] public Rporderdetails Rporderdetails { get; set; }
}
public class Rporderdetails [JsonProperty("rporderdetails", NullValueHandling = NullValueHandling.Ignore)]
{ public Rporderdetails Rporderdetails { get; set; }
[JsonProperty("@version", NullValueHandling = NullValueHandling.Ignore)] public string Version { get; set; } }
[JsonProperty("rpheader", NullValueHandling = NullValueHandling.Ignore)] public Rpheader Rpheader { get; set; }
[JsonProperty("order", NullValueHandling = NullValueHandling.Ignore)] public Order Order { get; set; }
}
public class Order public class Rporderdetails {
{ [JsonProperty("@version", NullValueHandling = NullValueHandling.Ignore)]
[JsonProperty("@cdt", NullValueHandling = NullValueHandling.Ignore)] public string Cdt { get; set; } public string Version { get; set; }
[JsonProperty("@cid", NullValueHandling = NullValueHandling.Ignore)] public string Cid { get; set; }
[JsonProperty("@ddt", NullValueHandling = NullValueHandling.Ignore)] public string Ddt { get; set; }
[JsonProperty("@fkat", NullValueHandling = NullValueHandling.Ignore)] public string Fkat { get; set; }
[JsonProperty("@ldt", NullValueHandling = NullValueHandling.Ignore)] public string Ldt { get; set; }
[JsonProperty("@on", NullValueHandling = NullValueHandling.Ignore)] public string On { get; set; }
[JsonProperty("@pg", NullValueHandling = NullValueHandling.Ignore)] public string Pg { get; set; }
[JsonProperty("@sdt", NullValueHandling = NullValueHandling.Ignore)] public string Sdt { get; set; }
[JsonProperty("@version", NullValueHandling = NullValueHandling.Ignore)] public string Version { get; set; }
[JsonProperty("@vfrom", NullValueHandling = NullValueHandling.Ignore)] public string Vfrom { get; set; }
[JsonProperty("@vto", NullValueHandling = NullValueHandling.Ignore)] public string Vto { get; set; }
[JsonProperty("@zweg", NullValueHandling = NullValueHandling.Ignore)] public string Zweg { get; set; }
[JsonProperty("tcklist", NullValueHandling = NullValueHandling.Ignore)] public Tcklist Tcklist { get; set; }
[JsonProperty("posinfolist", NullValueHandling = NullValueHandling.Ignore)] public Posinfolist Posinfolist { get; set; }
}
public class Posinfolist [JsonProperty("rpheader", NullValueHandling = NullValueHandling.Ignore)]
{ public Rpheader Rpheader { get; set; }
[JsonProperty("posinfo", NullValueHandling = NullValueHandling.Ignore)] public Posinfo Posinfo { get; set; }
}
public class Posinfo [JsonProperty("order", NullValueHandling = NullValueHandling.Ignore)]
{ public Order Order { get; set; }
[JsonProperty("@dir", NullValueHandling = NullValueHandling.Ignore)] public string Dir { get; set; } }
[JsonProperty("@dirlabel", NullValueHandling = NullValueHandling.Ignore)] public string Dirlabel { get; set; }
[JsonProperty("@posnr", NullValueHandling = NullValueHandling.Ignore)] public string Posnr { get; set; }
[JsonProperty("@shownr", NullValueHandling = NullValueHandling.Ignore)] public string Shownr { get; set; }
[JsonProperty("@state", NullValueHandling = NullValueHandling.Ignore)] public string State { get; set; }
[JsonProperty("@type", NullValueHandling = NullValueHandling.Ignore)] public string Type { get; set; }
[JsonProperty("@typeinfo", NullValueHandling = NullValueHandling.Ignore)] public string Typeinfo { get; set; }
[JsonProperty("@vfo", NullValueHandling = NullValueHandling.Ignore)] public string Vfo { get; set; }
[JsonProperty("@vto", NullValueHandling = NullValueHandling.Ignore)] public string Vto { get; set; }
[JsonProperty("childlist")] public object Childlist { get; set; }
}
public class Tcklist public class Order {
{ [JsonProperty("@cdt", NullValueHandling = NullValueHandling.Ignore)]
[JsonProperty("tck", NullValueHandling = NullValueHandling.Ignore)] public Tck Tck { get; set; } public string Cdt { get; set; }
}
public class Tck [JsonProperty("@cid", NullValueHandling = NullValueHandling.Ignore)]
{ public string Cid { get; set; }
[JsonProperty("@posnr", NullValueHandling = NullValueHandling.Ignore)] public string Posnr { get; set; }
[JsonProperty("htdata", NullValueHandling = NullValueHandling.Ignore)] public Htdata Htdata { get; set; }
[JsonProperty("mtk", NullValueHandling = NullValueHandling.Ignore)] public Mtk Mtk { get; set; }
[JsonProperty("bahncardimage", NullValueHandling = NullValueHandling.Ignore)] public Bahncardimage Bahncardimage { get; set; }
}
public class Bahncardimage [JsonProperty("@ddt", NullValueHandling = NullValueHandling.Ignore)]
{ public string Ddt { get; set; }
[JsonProperty("#cdata-section", NullValueHandling = NullValueHandling.Ignore)] public string CdataSection { get; set; }
}
public class Htdata [JsonProperty("@fkat", NullValueHandling = NullValueHandling.Ignore)]
{ public string Fkat { get; set; }
[JsonProperty("ht", NullValueHandling = NullValueHandling.Ignore)] public List<Ht> Ht { get; set; }
}
public class Ht [JsonProperty("@ldt", NullValueHandling = NullValueHandling.Ignore)]
{ public string Ldt { get; set; }
[JsonProperty("@name", NullValueHandling = NullValueHandling.Ignore)] public string Name { get; set; }
[JsonProperty("@pos", NullValueHandling = NullValueHandling.Ignore)] public string Pos { get; set; }
[JsonProperty("@type", NullValueHandling = NullValueHandling.Ignore)] public string Type { get; set; }
[JsonProperty("#text", NullValueHandling = NullValueHandling.Ignore)] public string Text { get; set; }
}
public class Mtk [JsonProperty("@on", NullValueHandling = NullValueHandling.Ignore)]
{ public string On { get; set; }
[JsonProperty("@dir", NullValueHandling = NullValueHandling.Ignore)] public string Dir { get; set; }
[JsonProperty("@status", NullValueHandling = NullValueHandling.Ignore)] public string Status { get; set; }
[JsonProperty("txt", NullValueHandling = NullValueHandling.Ignore)] public string Txt { get; set; }
[JsonProperty("zb", NullValueHandling = NullValueHandling.Ignore)] public string Zb { get; set; }
[JsonProperty("nvplist", NullValueHandling = NullValueHandling.Ignore)] public Nvplist Nvplist { get; set; }
}
public class Nvplist [JsonProperty("@pg", NullValueHandling = NullValueHandling.Ignore)]
{ public string Pg { get; set; }
[JsonProperty("nvp", NullValueHandling = NullValueHandling.Ignore)] public List<Nvp> Nvp { get; set; }
}
public class Nvp [JsonProperty("@sdt", NullValueHandling = NullValueHandling.Ignore)]
{ public string Sdt { get; set; }
[JsonProperty("@name", NullValueHandling = NullValueHandling.Ignore)] public string Name { get; set; }
[JsonProperty("#text", NullValueHandling = NullValueHandling.Ignore)] public string Text { get; set; }
}
public class Rpheader [JsonProperty("@version", NullValueHandling = NullValueHandling.Ignore)]
{ public string Version { get; set; }
[JsonProperty("@tnr", NullValueHandling = NullValueHandling.Ignore)] public string Tnr { get; set; }
[JsonProperty("@ts", NullValueHandling = NullValueHandling.Ignore)] public string Ts { get; set; }
}
public class Xml [JsonProperty("@vfrom", NullValueHandling = NullValueHandling.Ignore)]
{ public string Vfrom { get; set; }
[JsonProperty("@version", NullValueHandling = NullValueHandling.Ignore)] public string Version { get; set; }
[JsonProperty("@encoding", NullValueHandling = NullValueHandling.Ignore)] public string Encoding { get; set; }
}
public partial class CardResponse [JsonProperty("@vto", NullValueHandling = NullValueHandling.Ignore)]
{ public string Vto { get; set; }
public static CardResponse FromJson(string json) => JsonConvert.DeserializeObject<CardResponse>(json, Converter.Settings);
}
internal static class Converter [JsonProperty("@zweg", NullValueHandling = NullValueHandling.Ignore)]
{ public string Zweg { get; set; }
public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
{ [JsonProperty("tcklist", NullValueHandling = NullValueHandling.Ignore)]
MetadataPropertyHandling = MetadataPropertyHandling.Ignore, public Tcklist Tcklist { get; set; }
DateParseHandling = DateParseHandling.None,
Converters = [JsonProperty("posinfolist", NullValueHandling = NullValueHandling.Ignore)]
{ public Posinfolist Posinfolist { get; set; }
new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal } }
},
}; public class Posinfolist {
} [JsonProperty("posinfo", NullValueHandling = NullValueHandling.Ignore)]
} public Posinfo Posinfo { get; set; }
}
public class Posinfo {
[JsonProperty("@dir", NullValueHandling = NullValueHandling.Ignore)]
public string Dir { get; set; }
[JsonProperty("@dirlabel", NullValueHandling = NullValueHandling.Ignore)]
public string Dirlabel { get; set; }
[JsonProperty("@posnr", NullValueHandling = NullValueHandling.Ignore)]
public string Posnr { get; set; }
[JsonProperty("@shownr", NullValueHandling = NullValueHandling.Ignore)]
public string Shownr { get; set; }
[JsonProperty("@state", NullValueHandling = NullValueHandling.Ignore)]
public string State { get; set; }
[JsonProperty("@type", NullValueHandling = NullValueHandling.Ignore)]
public string Type { get; set; }
[JsonProperty("@typeinfo", NullValueHandling = NullValueHandling.Ignore)]
public string Typeinfo { get; set; }
[JsonProperty("@vfo", NullValueHandling = NullValueHandling.Ignore)]
public string Vfo { get; set; }
[JsonProperty("@vto", NullValueHandling = NullValueHandling.Ignore)]
public string Vto { get; set; }
[JsonProperty("childlist")] public object Childlist { get; set; }
}
public class Tcklist {
[JsonProperty("tck", NullValueHandling = NullValueHandling.Ignore)]
public Tck Tck { get; set; }
}
public class Tck {
[JsonProperty("@posnr", NullValueHandling = NullValueHandling.Ignore)]
public string Posnr { get; set; }
[JsonProperty("htdata", NullValueHandling = NullValueHandling.Ignore)]
public Htdata Htdata { get; set; }
[JsonProperty("mtk", NullValueHandling = NullValueHandling.Ignore)]
public Mtk Mtk { get; set; }
[JsonProperty("bahncardimage", NullValueHandling = NullValueHandling.Ignore)]
public Bahncardimage Bahncardimage { get; set; }
}
public class Bahncardimage {
[JsonProperty("#cdata-section", NullValueHandling = NullValueHandling.Ignore)]
public string CdataSection { get; set; }
}
public class Htdata {
[JsonProperty("ht", NullValueHandling = NullValueHandling.Ignore)]
public List<Ht> Ht { get; set; }
}
public class Ht {
[JsonProperty("@name", NullValueHandling = NullValueHandling.Ignore)]
public string Name { get; set; }
[JsonProperty("@pos", NullValueHandling = NullValueHandling.Ignore)]
public string Pos { get; set; }
[JsonProperty("@type", NullValueHandling = NullValueHandling.Ignore)]
public string Type { get; set; }
[JsonProperty("#text", NullValueHandling = NullValueHandling.Ignore)]
public string Text { get; set; }
}
public class Mtk {
[JsonProperty("@dir", NullValueHandling = NullValueHandling.Ignore)]
public string Dir { get; set; }
[JsonProperty("@status", NullValueHandling = NullValueHandling.Ignore)]
public string Status { get; set; }
[JsonProperty("txt", NullValueHandling = NullValueHandling.Ignore)]
public string Txt { get; set; }
[JsonProperty("zb", NullValueHandling = NullValueHandling.Ignore)]
public string Zb { get; set; }
[JsonProperty("nvplist", NullValueHandling = NullValueHandling.Ignore)]
public Nvplist Nvplist { get; set; }
}
public class Nvplist {
[JsonProperty("nvp", NullValueHandling = NullValueHandling.Ignore)]
public List<Nvp> Nvp { get; set; }
}
public class Nvp {
[JsonProperty("@name", NullValueHandling = NullValueHandling.Ignore)]
public string Name { get; set; }
[JsonProperty("#text", NullValueHandling = NullValueHandling.Ignore)]
public string Text { get; set; }
}
public class Rpheader {
[JsonProperty("@tnr", NullValueHandling = NullValueHandling.Ignore)]
public string Tnr { get; set; }
[JsonProperty("@ts", NullValueHandling = NullValueHandling.Ignore)]
public string Ts { get; set; }
}
public class Xml {
[JsonProperty("@version", NullValueHandling = NullValueHandling.Ignore)]
public string Version { get; set; }
[JsonProperty("@encoding", NullValueHandling = NullValueHandling.Ignore)]
public string Encoding { get; set; }
}
public partial class CardResponse {
public static CardResponse FromJson(string json) => JsonConvert.DeserializeObject<CardResponse>(json, Converter.Settings);
}
internal static class Converter {
public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings {
MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
DateParseHandling = DateParseHandling.None,
Converters = {new IsoDateTimeConverter {DateTimeStyles = DateTimeStyles.AssumeUniversal}}
};
}
}

View file

@ -9,53 +9,67 @@
using System.Collections.Generic; using System.Collections.Generic;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace bahnplan.web.JSON.ListOrdersResponse namespace bahnplan.web.JSON.ListOrdersResponse {
{ public partial class ListOrdersResponse {
public partial class ListOrdersResponse [JsonProperty("?xml", NullValueHandling = NullValueHandling.Ignore)]
{ public Xml Xml { get; set; }
[JsonProperty("?xml", NullValueHandling = NullValueHandling.Ignore)] public Xml Xml { get; set; }
[JsonProperty("rporderheadlist", NullValueHandling = NullValueHandling.Ignore)] public Rporderheadlist Rporderheadlist { get; set; }
}
public class Rporderheadlist [JsonProperty("rporderheadlist", NullValueHandling = NullValueHandling.Ignore)]
{ public Rporderheadlist Rporderheadlist { get; set; }
[JsonProperty("@version", NullValueHandling = NullValueHandling.Ignore)] public string Version { get; set; } }
[JsonProperty("rpheader", NullValueHandling = NullValueHandling.Ignore)] public Rpheader Rpheader { get; set; }
[JsonProperty("orderheadlist", NullValueHandling = NullValueHandling.Ignore)] public Orderheadlist Orderheadlist { get; set; }
}
public class Orderheadlist public class Rporderheadlist {
{ [JsonProperty("@version", NullValueHandling = NullValueHandling.Ignore)]
[JsonProperty("orderhead", NullValueHandling = NullValueHandling.Ignore)] public List<Orderhead> Orderhead { get; set; } public string Version { get; set; }
}
public class Orderhead [JsonProperty("rpheader", NullValueHandling = NullValueHandling.Ignore)]
{ public Rpheader Rpheader { get; set; }
[JsonProperty("@ldt", NullValueHandling = NullValueHandling.Ignore)] public string Ldt { get; set; }
[JsonProperty("@on", NullValueHandling = NullValueHandling.Ignore)] public string On { get; set; }
[JsonProperty("authtmp", NullValueHandling = NullValueHandling.Ignore)] public Authtmp Authtmp { get; set; }
}
public class Authtmp [JsonProperty("orderheadlist", NullValueHandling = NullValueHandling.Ignore)]
{ public Orderheadlist Orderheadlist { get; set; }
[JsonProperty("@htmp", NullValueHandling = NullValueHandling.Ignore)] public string Htmp { get; set; } }
[JsonProperty("@ts", NullValueHandling = NullValueHandling.Ignore)] public string Ts { get; set; }
}
public class Rpheader public class Orderheadlist {
{ [JsonProperty("orderhead", NullValueHandling = NullValueHandling.Ignore)]
[JsonProperty("@tnr", NullValueHandling = NullValueHandling.Ignore)] public string Tnr { get; set; } public List<Orderhead> Orderhead { get; set; }
[JsonProperty("@ts", NullValueHandling = NullValueHandling.Ignore)] public string Ts { get; set; } }
}
public class Xml public class Orderhead {
{ [JsonProperty("@ldt", NullValueHandling = NullValueHandling.Ignore)]
[JsonProperty("@version", NullValueHandling = NullValueHandling.Ignore)] public string Version { get; set; } public string Ldt { get; set; }
[JsonProperty("@encoding", NullValueHandling = NullValueHandling.Ignore)] public string Encoding { get; set; }
}
public partial class ListOrdersResponse [JsonProperty("@on", NullValueHandling = NullValueHandling.Ignore)]
{ public string On { get; set; }
public static ListOrdersResponse FromJson(string json) => JsonConvert.DeserializeObject<ListOrdersResponse>(json, Converter.Settings);
} [JsonProperty("authtmp", NullValueHandling = NullValueHandling.Ignore)]
} public Authtmp Authtmp { get; set; }
}
public class Authtmp {
[JsonProperty("@htmp", NullValueHandling = NullValueHandling.Ignore)]
public string Htmp { get; set; }
[JsonProperty("@ts", NullValueHandling = NullValueHandling.Ignore)]
public string Ts { get; set; }
}
public class Rpheader {
[JsonProperty("@tnr", NullValueHandling = NullValueHandling.Ignore)]
public string Tnr { get; set; }
[JsonProperty("@ts", NullValueHandling = NullValueHandling.Ignore)]
public string Ts { get; set; }
}
public class Xml {
[JsonProperty("@version", NullValueHandling = NullValueHandling.Ignore)]
public string Version { get; set; }
[JsonProperty("@encoding", NullValueHandling = NullValueHandling.Ignore)]
public string Encoding { get; set; }
}
public partial class ListOrdersResponse {
public static ListOrdersResponse FromJson(string json) => JsonConvert.DeserializeObject<ListOrdersResponse>(json, Converter.Settings);
}
}

View file

@ -9,151 +9,254 @@
using System.Collections.Generic; using System.Collections.Generic;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace bahnplan.web.JSON namespace bahnplan.web.JSON {
{ using J = JsonPropertyAttribute;
using J = JsonPropertyAttribute; using R = Required;
using R = Required; using N = NullValueHandling;
using N = NullValueHandling;
public partial class OeapiResponse public partial class OeapiResponse {
{ [J("status", NullValueHandling = N.Ignore)]
[J("status", NullValueHandling = N.Ignore)] public string Status { get; set; } public string Status { get; set; }
[J("msg", NullValueHandling = N.Ignore)] public string Msg { get; set; }
[J("data", NullValueHandling = N.Ignore)] public Data Data { get; set; }
}
public class Data [J("msg", NullValueHandling = N.Ignore)]
{ public string Msg { get; set; }
[J("reqId", NullValueHandling = N.Ignore)] public string ReqId { get; set; }
[J("lastUpdated", NullValueHandling = N.Ignore)] public long? LastUpdated { get; set; }
[J("params", NullValueHandling = N.Ignore)] public Params Params { get; set; }
[J("journeys", NullValueHandling = N.Ignore)] public Dictionary<string, OJourney> Journeys { get; set; }
}
public class OJourney [J("data", NullValueHandling = N.Ignore)]
{ public Data Data { get; set; }
[J("lastUpdated", NullValueHandling = N.Ignore)] public long? LastUpdated { get; set; } }
[J("legs", NullValueHandling = N.Ignore)] public List<Leg> Legs { get; set; }
[J("price")] public object Price { get; set; }
}
public class Leg public class Data {
{ [J("reqId", NullValueHandling = N.Ignore)]
[J("isWalking", NullValueHandling = N.Ignore)] public bool? IsWalking { get; set; } public string ReqId { get; set; }
[J("isTransfer", NullValueHandling = N.Ignore)] public bool? IsTransfer { get; set; }
[J("cancelled", NullValueHandling = N.Ignore)] public bool? Cancelled { get; set; }
[J("departure", NullValueHandling = N.Ignore)] public Arrival Departure { get; set; }
[J("arrival", NullValueHandling = N.Ignore)] public Arrival Arrival { get; set; }
[J("polyline")] public object Polyline { get; set; }
[J("distance")] public object Distance { get; set; }
[J("line", NullValueHandling = N.Ignore)] public Line Line { get; set; }
[J("direction", NullValueHandling = N.Ignore)] public string Direction { get; set; }
[J("stopovers", NullValueHandling = N.Ignore)] public List<Stopover> Stopovers { get; set; }
[J("remarks", NullValueHandling = N.Ignore)] public List<Remark> Remarks { get; set; }
}
public class Arrival [J("lastUpdated", NullValueHandling = N.Ignore)]
{ public long? LastUpdated { get; set; }
[J("point", NullValueHandling = N.Ignore)] public Point Point { get; set; }
[J("plannedTime")] public long? PlannedTime { get; set; }
[J("prognosedTime")] public long? PrognosedTime { get; set; }
[J("plannedPlatform")] public string PlannedPlatform { get; set; }
[J("prognosedPlatform")] public object PrognosedPlatform { get; set; }
}
public class Point [J("params", NullValueHandling = N.Ignore)]
{ public Params Params { get; set; }
[J("stop", NullValueHandling = N.Ignore)] public Stop Stop { get; set; }
[J("location")] public object Location { get; set; }
}
public class Stop [J("journeys", NullValueHandling = N.Ignore)]
{ public Dictionary<string, OJourney> Journeys { get; set; }
[J("id", NullValueHandling = N.Ignore)] public string Id { get; set; } }
[J("name", NullValueHandling = N.Ignore)] public string Name { get; set; }
[J("location", NullValueHandling = N.Ignore)] public Location Location { get; set; }
[J("products", NullValueHandling = N.Ignore)] public Products Products { get; set; }
[J("station")] public object Station { get; set; }
}
public class Location public class OJourney {
{ [J("lastUpdated", NullValueHandling = N.Ignore)]
[J("latitude", NullValueHandling = N.Ignore)] public double? Latitude { get; set; } public long? LastUpdated { get; set; }
[J("longitude", NullValueHandling = N.Ignore)] public double? Longitude { get; set; }
[J("name")] public object Name { get; set; }
[J("address")] public object Address { get; set; }
[J("id")] public object Id { get; set; }
}
public class Products [J("legs", NullValueHandling = N.Ignore)]
{ public List<Leg> Legs { get; set; }
[J("nationalExp", NullValueHandling = N.Ignore)] public bool? NationalExp { get; set; }
[J("national", NullValueHandling = N.Ignore)] public bool? National { get; set; }
[J("regionalExp", NullValueHandling = N.Ignore)] public bool? RegionalExp { get; set; }
[J("regional", NullValueHandling = N.Ignore)] public bool? Regional { get; set; }
[J("suburban", NullValueHandling = N.Ignore)] public bool? Suburban { get; set; }
[J("bus", NullValueHandling = N.Ignore)] public bool? Bus { get; set; }
[J("ferry", NullValueHandling = N.Ignore)] public bool? Ferry { get; set; }
[J("subway", NullValueHandling = N.Ignore)] public bool? Subway { get; set; }
[J("tram", NullValueHandling = N.Ignore)] public bool? Tram { get; set; }
[J("taxi", NullValueHandling = N.Ignore)] public bool? Taxi { get; set; }
}
public class Line [J("price")] public object Price { get; set; }
{ }
[J("id", NullValueHandling = N.Ignore)] public string Id { get; set; }
[J("name", NullValueHandling = N.Ignore)] public string Name { get; set; }
[J("mode", NullValueHandling = N.Ignore)] public string Mode { get; set; }
[J("product", NullValueHandling = N.Ignore)] public string Product { get; set; }
[J("tripNum", NullValueHandling = N.Ignore)] public string TripNum { get; set; }
[J("productName", NullValueHandling = N.Ignore)] public string ProductName { get; set; }
[J("fullProductName", NullValueHandling = N.Ignore)] public string FullProductName { get; set; }
[J("operator")] public object Operator { get; set; }
[J("additionalName")] public string AdditionalName { get; set; }
}
public class Remark public class Leg {
{ [J("isWalking", NullValueHandling = N.Ignore)]
[J("type", NullValueHandling = N.Ignore)] public string Type { get; set; } public bool? IsWalking { get; set; }
[J("code", NullValueHandling = N.Ignore)] public string Code { get; set; }
[J("summary")] public string Summary { get; set; }
[J("text", NullValueHandling = N.Ignore)] public string Text { get; set; }
[J("tripId")] public object TripId { get; set; }
}
public class Stopover [J("isTransfer", NullValueHandling = N.Ignore)]
{ public bool? IsTransfer { get; set; }
[J("stop", NullValueHandling = N.Ignore)] public Stop Stop { get; set; }
[J("cancelled", NullValueHandling = N.Ignore)] public bool? Cancelled { get; set; }
[J("departure", NullValueHandling = N.Ignore)] public Arrival Departure { get; set; }
[J("arrival", NullValueHandling = N.Ignore)] public Arrival Arrival { get; set; }
}
public class Params [J("cancelled", NullValueHandling = N.Ignore)]
{ public bool? Cancelled { get; set; }
[J("fromPoint", NullValueHandling = N.Ignore)] public Point FromPoint { get; set; }
[J("toPoint", NullValueHandling = N.Ignore)] public Point ToPoint { get; set; }
[J("viaPoint")] public object ViaPoint { get; set; }
[J("earlierRef")] public object EarlierRef { get; set; }
[J("laterRef")] public object LaterRef { get; set; }
[J("results")] public object Results { get; set; }
[J("stopovers", NullValueHandling = N.Ignore)] public bool? Stopovers { get; set; }
[J("polylines", NullValueHandling = N.Ignore)] public bool? Polylines { get; set; }
[J("remarks", NullValueHandling = N.Ignore)] public bool? Remarks { get; set; }
[J("bikeFriendly")] public object BikeFriendly { get; set; }
[J("tickets", NullValueHandling = N.Ignore)] public bool? Tickets { get; set; }
[J("startWithWalking")] public object StartWithWalking { get; set; }
[J("scheduledDays")] public object ScheduledDays { get; set; }
[J("accessibility", NullValueHandling = N.Ignore)] public string Accessibility { get; set; }
[J("transfers")] public object Transfers { get; set; }
[J("transferTime")] public object TransferTime { get; set; }
[J("arrival")] public object Arrival { get; set; }
[J("departure", NullValueHandling = N.Ignore)] public long? Departure { get; set; }
[J("products", NullValueHandling = N.Ignore)] public Products Products { get; set; }
}
public partial class OeapiResponse [J("departure", NullValueHandling = N.Ignore)]
{ public Arrival Departure { get; set; }
public static OeapiResponse FromJson(string json) => JsonConvert.DeserializeObject<OeapiResponse>(json, Converter.Settings);
} [J("arrival", NullValueHandling = N.Ignore)]
} public Arrival Arrival { get; set; }
[J("polyline")] public object Polyline { get; set; }
[J("distance")] public object Distance { get; set; }
[J("line", NullValueHandling = N.Ignore)]
public Line Line { get; set; }
[J("direction", NullValueHandling = N.Ignore)]
public string Direction { get; set; }
[J("stopovers", NullValueHandling = N.Ignore)]
public List<Stopover> Stopovers { get; set; }
[J("remarks", NullValueHandling = N.Ignore)]
public List<Remark> Remarks { get; set; }
}
public class Arrival {
[J("point", NullValueHandling = N.Ignore)]
public Point Point { get; set; }
[J("plannedTime")] public long? PlannedTime { get; set; }
[J("prognosedTime")] public long? PrognosedTime { get; set; }
[J("plannedPlatform")] public string PlannedPlatform { get; set; }
[J("prognosedPlatform")] public object PrognosedPlatform { get; set; }
}
public class Point {
[J("stop", NullValueHandling = N.Ignore)]
public Stop Stop { get; set; }
[J("location")] public object Location { get; set; }
}
public class Stop {
[J("id", NullValueHandling = N.Ignore)]
public string Id { get; set; }
[J("name", NullValueHandling = N.Ignore)]
public string Name { get; set; }
[J("location", NullValueHandling = N.Ignore)]
public Location Location { get; set; }
[J("products", NullValueHandling = N.Ignore)]
public Products Products { get; set; }
[J("station")] public object Station { get; set; }
}
public class Location {
[J("latitude", NullValueHandling = N.Ignore)]
public double? Latitude { get; set; }
[J("longitude", NullValueHandling = N.Ignore)]
public double? Longitude { get; set; }
[J("name")] public object Name { get; set; }
[J("address")] public object Address { get; set; }
[J("id")] public object Id { get; set; }
}
public class Products {
[J("nationalExp", NullValueHandling = N.Ignore)]
public bool? NationalExp { get; set; }
[J("national", NullValueHandling = N.Ignore)]
public bool? National { get; set; }
[J("regionalExp", NullValueHandling = N.Ignore)]
public bool? RegionalExp { get; set; }
[J("regional", NullValueHandling = N.Ignore)]
public bool? Regional { get; set; }
[J("suburban", NullValueHandling = N.Ignore)]
public bool? Suburban { get; set; }
[J("bus", NullValueHandling = N.Ignore)]
public bool? Bus { get; set; }
[J("ferry", NullValueHandling = N.Ignore)]
public bool? Ferry { get; set; }
[J("subway", NullValueHandling = N.Ignore)]
public bool? Subway { get; set; }
[J("tram", NullValueHandling = N.Ignore)]
public bool? Tram { get; set; }
[J("taxi", NullValueHandling = N.Ignore)]
public bool? Taxi { get; set; }
}
public class Line {
[J("id", NullValueHandling = N.Ignore)]
public string Id { get; set; }
[J("name", NullValueHandling = N.Ignore)]
public string Name { get; set; }
[J("mode", NullValueHandling = N.Ignore)]
public string Mode { get; set; }
[J("product", NullValueHandling = N.Ignore)]
public string Product { get; set; }
[J("tripNum", NullValueHandling = N.Ignore)]
public string TripNum { get; set; }
[J("productName", NullValueHandling = N.Ignore)]
public string ProductName { get; set; }
[J("fullProductName", NullValueHandling = N.Ignore)]
public string FullProductName { get; set; }
[J("operator")] public object Operator { get; set; }
[J("additionalName")] public string AdditionalName { get; set; }
}
public class Remark {
[J("type", NullValueHandling = N.Ignore)]
public string Type { get; set; }
[J("code", NullValueHandling = N.Ignore)]
public string Code { get; set; }
[J("summary")] public string Summary { get; set; }
[J("text", NullValueHandling = N.Ignore)]
public string Text { get; set; }
[J("tripId")] public object TripId { get; set; }
}
public class Stopover {
[J("stop", NullValueHandling = N.Ignore)]
public Stop Stop { get; set; }
[J("cancelled", NullValueHandling = N.Ignore)]
public bool? Cancelled { get; set; }
[J("departure", NullValueHandling = N.Ignore)]
public Arrival Departure { get; set; }
[J("arrival", NullValueHandling = N.Ignore)]
public Arrival Arrival { get; set; }
}
public class Params {
[J("fromPoint", NullValueHandling = N.Ignore)]
public Point FromPoint { get; set; }
[J("toPoint", NullValueHandling = N.Ignore)]
public Point ToPoint { get; set; }
[J("viaPoint")] public object ViaPoint { get; set; }
[J("earlierRef")] public object EarlierRef { get; set; }
[J("laterRef")] public object LaterRef { get; set; }
[J("results")] public object Results { get; set; }
[J("stopovers", NullValueHandling = N.Ignore)]
public bool? Stopovers { get; set; }
[J("polylines", NullValueHandling = N.Ignore)]
public bool? Polylines { get; set; }
[J("remarks", NullValueHandling = N.Ignore)]
public bool? Remarks { get; set; }
[J("bikeFriendly")] public object BikeFriendly { get; set; }
[J("tickets", NullValueHandling = N.Ignore)]
public bool? Tickets { get; set; }
[J("startWithWalking")] public object StartWithWalking { get; set; }
[J("scheduledDays")] public object ScheduledDays { get; set; }
[J("accessibility", NullValueHandling = N.Ignore)]
public string Accessibility { get; set; }
[J("transfers")] public object Transfers { get; set; }
[J("transferTime")] public object TransferTime { get; set; }
[J("arrival")] public object Arrival { get; set; }
[J("departure", NullValueHandling = N.Ignore)]
public long? Departure { get; set; }
[J("products", NullValueHandling = N.Ignore)]
public Products Products { get; set; }
}
public partial class OeapiResponse {
public static OeapiResponse FromJson(string json) => JsonConvert.DeserializeObject<OeapiResponse>(json, Converter.Settings);
}
}

View file

@ -246,8 +246,7 @@ namespace bahnplan.web.JSON {
} }
public class Trainlist { public class Trainlist {
[J("train", NullValueHandling = NV.Ignore)] [J("train", NullValueHandling = NV.Ignore), JsonConverter(typeof(SingleOrArrayConverter<Train>))]
[JsonConverter(typeof(SingleOrArrayConverter<Train>))]
public List<Train> Train { get; set; } public List<Train> Train { get; set; }
} }
@ -411,22 +410,20 @@ namespace bahnplan.web.JSON {
public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings { public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings {
MetadataPropertyHandling = MetadataPropertyHandling.Ignore, MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
DateParseHandling = DateParseHandling.None, DateParseHandling = DateParseHandling.None,
Converters = {new IsoDateTimeConverter {DateTimeStyles = DateTimeStyles.AssumeUniversal}}, Converters = {new IsoDateTimeConverter {DateTimeStyles = DateTimeStyles.AssumeUniversal}}
}; };
} }
internal class SingleOrArrayConverter<T> : JsonConverter { internal class SingleOrArrayConverter<T> : JsonConverter {
public override bool CanConvert(Type objectType) { public override bool CanWrite => false;
return objectType == typeof(List<T>);
} public override bool CanConvert(Type objectType) => objectType == typeof(List<T>);
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) {
var token = JToken.Load(reader); var token = JToken.Load(reader);
return token.Type == JTokenType.Array ? token.ToObject<List<T>>() : new List<T> {token.ToObject<T>()}; return token.Type == JTokenType.Array ? token.ToObject<List<T>>() : new List<T> {token.ToObject<T>()};
} }
public override bool CanWrite => false;
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) {
throw new NotImplementedException(); throw new NotImplementedException();
} }

View file

@ -5,7 +5,7 @@
@{ @{
ViewData["Title"] = "Card"; ViewData["Title"] = "Card";
Response.Redirect("/Cards"); Response.Redirect("/Cards");
if (HttpContext.Session.GetString("authorized") != "true") { if (HttpContext.Session.GetString("authorized") != "true") {
Response.Redirect("/"); Response.Redirect("/");
return; return;

View file

@ -4,22 +4,19 @@ using System.Xml;
using System.Xml.Linq; using System.Xml.Linq;
using bahnplan.web.database; using bahnplan.web.database;
using bahnplan.web.database.Tables; using bahnplan.web.database.Tables;
using bahnplan.web.JSON;
using bahnplan.web.JSON.CardResponse; using bahnplan.web.JSON.CardResponse;
using bahnplan.web.JSON.ListOrdersResponse; using bahnplan.web.JSON.ListOrdersResponse;
using LinqToDB; using LinqToDB;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.Mvc.RazorPages;
using Newtonsoft.Json; using Newtonsoft.Json;
using Leg = bahnplan.web.database.Tables.Leg;
namespace bahnplan.web.Pages { namespace bahnplan.web.Pages {
public class CardModel : PageModel { public class CardModel : PageModel {
public void OnPost() { public void OnPost() {
if (HttpContext.Session.GetString("authorized") != "true") { if (HttpContext.Session.GetString("authorized") != "true")
return; return;
}
using var db = new Database.DbConn(); using var db = new Database.DbConn();
var request = new XDocument(new XElement("rqorderheadlist", var request = new XDocument(new XElement("rqorderheadlist",
new XElement("rqheader", new XAttribute("ts", "2020-02-19T15:59:00"), new XAttribute("l", "de"), new XElement("rqheader", new XAttribute("ts", "2020-02-19T15:59:00"), new XAttribute("l", "de"),
@ -63,7 +60,7 @@ namespace bahnplan.web.Pages {
ValidFrom = parsedCard.Rporderdetails.Order.Vfrom, ValidFrom = parsedCard.Rporderdetails.Order.Vfrom,
ValidTo = parsedCard.Rporderdetails.Order.Vto, ValidTo = parsedCard.Rporderdetails.Order.Vto,
QrValidFrom = parsedCard.Rporderdetails.Order.Tcklist.Tck.Mtk.Nvplist.Nvp.First(p => p.Name == "ebcbarcodegueltigab").Text, QrValidFrom = parsedCard.Rporderdetails.Order.Tcklist.Tck.Mtk.Nvplist.Nvp.First(p => p.Name == "ebcbarcodegueltigab").Text,
QrValidTo = parsedCard.Rporderdetails.Order.Tcklist.Tck.Mtk.Nvplist.Nvp.First(p => p.Name == "ebcbarcodegueltigbis").Text, QrValidTo = parsedCard.Rporderdetails.Order.Tcklist.Tck.Mtk.Nvplist.Nvp.First(p => p.Name == "ebcbarcodegueltigbis").Text
}); });
} }
} }

View file

@ -8,37 +8,140 @@
Response.Redirect("/"); Response.Redirect("/");
return; return;
} }
if (Request.Query.ContainsKey("refresh")) {
Response.Redirect("?edit=true");
return;
}
} }
@foreach (var card in Model.Cards) { @if (Request.Query["edit"] == "true") {
<img src="@card.CardQr" alt="Ticketcode"/> <table class="table table-striped">
<img src="@card.CardSecCode" alt="Sichtmerkmal"/> <thead>
<a href="/Delete?item=card&id=@card.CardId"> <tr>
<img style="margin: -50px; height: 450px; transform: rotate(-90deg); position: relative; left: 130px" src='data:image/svg+xml;base64,@card.CardImage.Base64Encode()' alt="Bahncardimage"/> <th>Card</th>
</a> <th>Number</th>
<th>Traveller</th>
<th>Card Validity</th>
<th>QR Validity</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach (var card in Model.Cards) {
<tr>
<td>@card.CardInfo.TrimEnd('#')</td>
<td>@card.CardNumber</td>
<td>@card.Traveller</td>
<td>
@{
var from = DateTime.Parse(card.ValidFrom);
var to = DateTime.Parse(card.ValidTo);
if (from > DateTime.Now) {
<span style="color: red">
@card.ValidFrom.Split("T")[0]
</span>
}
else {
@card.ValidFrom.Split("T")[0]
}
<br/>
if (to < DateTime.Now) {
<span style="color: red">
@card.ValidTo.Split("T")[0]
</span>
}
else {
@card.ValidTo.Split("T")[0]
}
}
</td>
<td>
@{
var qrfrom = DateTime.Parse(card.QrValidFrom);
var qrto = DateTime.Parse(card.QrValidTo);
if (qrfrom > DateTime.Now) {
<span style="color: red">
@card.QrValidFrom.Split("T")[0]
</span>
}
else {
@card.QrValidFrom.Split("T")[0]
}
<br/>
if (qrto < DateTime.Now) {
<span style="color: red">
@card.QrValidTo.Split("T")[0]
</span>
}
else {
@card.QrValidTo.Split("T")[0]
}
}
</td>
<td>
<a class="btn btn-sm btn-primary" href="?refresh=@card.CardId">Refresh QR</a>
<a class="btn btn-sm btn-outline-danger" href="/Delete?item=card&id=@card.CardId">Delete</a>
</td>
</tr>
}
</tbody>
</table>
<a class="btn btn-sm btn-secondary" href="@Request.Path">Back</a>
<br/>
<br/>
<br/> <br/>
} }
<p style="text-align: right"> else if (Model.Cards.Any()) {
Click on the BahnCard Image to remove a card. foreach (var card in Model.Cards) {
</p> <img src="@card.CardQr" alt="Ticketcode"/>
<br/> <img src="@card.CardSecCode" alt="Sichtmerkmal"/>
<br/> <img style="margin: -50px; height: 450px; transform: rotate(-90deg); position: relative; left: 130px" src='data:image/svg+xml;base64,@card.CardImage.Base64Encode()' alt="Bahncardimage"/>
<br/> var from = DateTime.Parse(card.ValidFrom);
<br/> var to = DateTime.Parse(card.ValidTo);
<br/> var qrfrom = DateTime.Parse(card.QrValidFrom);
<br/> var qrto = DateTime.Parse(card.QrValidTo);
<h3>Get Cards from bahn.de account</h3>
<br/> if (from > DateTime.Now) {
<form method="POST" action="/Card"> <div class="alert alert-info" role="alert">
<div class="form-group"> The above card is not valid yet.
<input type="text" class="form-control" id="InputUser" name="user" placeholder="bahn.de username"> </div>
</div> }
<div class="form-group"> if (to < DateTime.Now) {
<input type="password" class="form-control" id="InputPassword" name="pass" placeholder="bahn.de password"> <div class="alert alert-warning" role="alert">
</div> The above card is expired.
<div class="form-group"> </div>
<input type="text" class="form-control" id="inputName" name="name" placeholder="Last name of traveller"> }
</div> if (qrfrom > DateTime.Now && !(from > DateTime.Now)) {
@Html.AntiForgeryToken() <div class="alert alert-info" role="alert">
<button type="submit" class="btn btn-primary">Submit</button> The above QR code is somehow not valid yet. Congrats, please open a bug report.
</form> </div>
}
if (qrto < DateTime.Now) {
<div class="alert alert-warning" role="alert">
The above QR code is expired. Please refresh the card. <a href="/Cards?edit=true">You can do that now</a>.
</div>
}
<br/>
}
<br/>
<a class="btn btn-sm btn-secondary" href="?edit=true">Edit cards</a>
}
@if (!Model.Cards.Any() || Request.Query["edit"] == "true") {
<h3>Get Cards from bahn.de account</h3>
<br/>
<form method="POST" action="/Card">
<div class="form-group">
<input type="text" class="form-control" id="InputUser" name="user" placeholder="bahn.de username">
</div>
<div class="form-group">
<input type="password" class="form-control" id="InputPassword" name="pass" placeholder="bahn.de password">
</div>
<div class="form-group">
<input type="text" class="form-control" id="inputName" name="name" placeholder="Last name of traveller">
</div>
@Html.AntiForgeryToken()
<button type="submit" class="btn btn-primary">Submit</button>
</form>
}

View file

@ -1,20 +1,51 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Net;
using System.Xml;
using System.Xml.Linq;
using bahnplan.web.database; using bahnplan.web.database;
using bahnplan.web.database.Tables; using bahnplan.web.database.Tables;
using bahnplan.web.JSON.CardResponse;
using LinqToDB;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.Mvc.RazorPages;
using Newtonsoft.Json;
namespace bahnplan.web.Pages { namespace bahnplan.web.Pages {
public class CardsModel : PageModel { public class CardsModel : PageModel {
public List<Card> Cards; public List<Card> Cards;
public void OnGet() { public void OnGet() {
if (HttpContext.Session.GetString("authorized") != "true") { if (HttpContext.Session.GetString("authorized") != "true")
return;
using var db = new Database.DbConn();
if (Request.Query.ContainsKey("refresh")) {
var card = db.Cards.First(p => p.CardId == int.Parse(Request.Query["refresh"]));
var request = new XDocument(new XElement("rqorderdetails", new XAttribute("version", "1.0"),
new XElement("rqheader", new XAttribute("ts", "2019-10-31T23:20:48"), new XAttribute("l", "de"),
new XAttribute("v", "19100000"), new XAttribute("d", "iPad7,5"),
new XAttribute("os", "iOS_13.1.3"), new XAttribute("app", "NAVIGATOR")),
new XElement("rqorder", new XAttribute("on", card.OrderId)),
new XElement("authname", new XAttribute("tln", card.Traveller.Split(" ").Last())))).ToString();
var response = new WebClient().UploadString("https://fahrkarten.bahn.de/mobile/dbc/xs.go", "POST", request);
var xmlobj = new XmlDocument();
xmlobj.LoadXml(response);
var json = JsonConvert.SerializeXmlNode(xmlobj);
var parsedCard = CardResponse.FromJson(json);
card.CardQr = parsedCard.Rporderdetails.Order.Tcklist.Tck.Htdata.Ht.First(p => p.Name == "barcode").Text;
card.CardSecCode = parsedCard.Rporderdetails.Order.Tcklist.Tck.Htdata.Ht.First(p => p.Name == "sichtmerkmal").Text;
card.CardImage = parsedCard.Rporderdetails.Order.Tcklist.Tck.Bahncardimage.CdataSection;
card.QrValidFrom = parsedCard.Rporderdetails.Order.Tcklist.Tck.Mtk.Nvplist.Nvp.First(p => p.Name == "ebcbarcodegueltigab").Text;
card.QrValidTo = parsedCard.Rporderdetails.Order.Tcklist.Tck.Mtk.Nvplist.Nvp.First(p => p.Name == "ebcbarcodegueltigbis").Text;
db.Update(card);
return; return;
} }
using var db = new Database.DbConn();
Cards = db.Cards.Where(p => p.UserId == int.Parse(HttpContext.Session.GetString("uid"))).ToList(); Cards = db.Cards.Where(p => p.UserId == int.Parse(HttpContext.Session.GetString("uid"))).ToList();
} }
} }

View file

@ -1,7 +1,6 @@
@page @page
@using Microsoft.AspNetCore.Http @using Microsoft.AspNetCore.Http
@using bahnplan.web.database @using bahnplan.web.database
@using System.Linq
@model DeleteModel @model DeleteModel
@{ @{
ViewData["Title"] = "Home"; ViewData["Title"] = "Home";
@ -13,19 +12,19 @@
if (Request.Query.ContainsKey("confirm") && Request.Query["confirm"] == "true") { if (Request.Query.ContainsKey("confirm") && Request.Query["confirm"] == "true") {
Layout = null; Layout = null;
Response.Redirect(Request.Headers["Referer"]); Response.Redirect("/");
return;
} }
else { <h3>Are you sure?</h3>
<h3>Are you sure?</h3> <p>
<p> You are attempting to delete
You are attempting to delete @{
@{ await using var db = new Database.DbConn();
await using var db = new Database.DbConn();
} switch (Request.Query["item"]) {
@switch (Request.Query["item"]) {
case "trip": { case "trip": {
var legs = db.Legs.Where(p => p.TripId == int.Parse(Request.Query["id"])).OrderBy(p => p.DepTime).ToList();; var legs = db.Legs.Where(p => p.TripId == int.Parse(Request.Query["id"])).OrderBy(p => p.DepTime).ToList();
<span> <span>
the trip from <b>@legs.First().DepStation</b> to <b>@legs.Last().ArrStation</b>, starting <i>@legs.First().DepTime</i> the trip from <b>@legs.First().DepStation</b> to <b>@legs.Last().ArrStation</b>, starting <i>@legs.First().DepTime</i>
@ -48,8 +47,8 @@
break; break;
} }
} }
</p> }
<a href="@Request.Headers["Referer"]" class="btn btn-sm btn-secondary">Cancel</a> </p>
<a href="/Delete?item=@Request.Query["item"]&id=@Request.Query["id"]&confirm=true" class="btn btn-sm btn-danger">Confirm</a> <a href="@Request.Headers["Referer"]" class="btn btn-sm btn-secondary">Cancel</a>
} <a href="/Delete?item=@Request.Query["item"]&id=@Request.Query["id"]&confirm=true" class="btn btn-sm btn-danger">Confirm</a>
} }

View file

@ -1,14 +1,9 @@
using System; using System.Linq;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using bahnplan.web.database; using bahnplan.web.database;
using bahnplan.web.database.Tables; using bahnplan.web.database.Tables;
using LinqToDB; using LinqToDB;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.Logging;
namespace bahnplan.web.Pages { namespace bahnplan.web.Pages {
public class DeleteModel : PageModel { public class DeleteModel : PageModel {

View file

@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
@ -10,16 +6,14 @@ using Microsoft.Extensions.Logging;
namespace bahnplan.web.Pages { namespace bahnplan.web.Pages {
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public class ErrorModel : PageModel { public class ErrorModel : PageModel {
private readonly ILogger<ErrorModel> _logger;
public ErrorModel(ILogger<ErrorModel> logger) => _logger = logger;
public string RequestId { get; set; } public string RequestId { get; set; }
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
private readonly ILogger<ErrorModel> _logger;
public ErrorModel(ILogger<ErrorModel> logger) {
_logger = logger;
}
public void OnGet() { public void OnGet() {
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier; RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
} }

View file

@ -1,7 +1,6 @@
@page @page
@using Microsoft.AspNetCore.Http @using Microsoft.AspNetCore.Http
@using bahnplan.web.database @using bahnplan.web.database
@using System.Linq
@model IndexModel @model IndexModel
@{ @{
ViewData["Title"] = "Home"; ViewData["Title"] = "Home";

View file

@ -1,13 +1,8 @@
using System; using System.Linq;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using bahnplan.web.database; using bahnplan.web.database;
using bahnplan.web.database.Tables; using bahnplan.web.database.Tables;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.Logging;
namespace bahnplan.web.Pages { namespace bahnplan.web.Pages {
public class IndexModel : PageModel { public class IndexModel : PageModel {

View file

@ -1,10 +1,10 @@
@page @page
@using bahnplan.web.database
@using Microsoft.AspNetCore.Http @using Microsoft.AspNetCore.Http
@using bahnplan.web.database
@model InspectionModel @model InspectionModel
@{ @{
ViewData["Title"] = "Inspection"; ViewData["Title"] = "Inspection";
if (HttpContext.Session.GetString("authorized") != "true") { if (HttpContext.Session.GetString("authorized") != "true") {
Response.Redirect("/"); Response.Redirect("/");
return; return;
@ -29,6 +29,32 @@
<img src="@card.CardQr" alt="Ticketcode"/> <img src="@card.CardQr" alt="Ticketcode"/>
<img src="@card.CardSecCode" alt="Sichtmerkmal"/> <img src="@card.CardSecCode" alt="Sichtmerkmal"/>
<img style="margin: -50px; height: 450px; transform: rotate(-90deg); position: relative; left: 130px" src='data:image/svg+xml;base64,@card.CardImage.Base64Encode()' alt="Bahncardimage"/> <img style="margin: -50px; height: 450px; transform: rotate(-90deg); position: relative; left: 130px" src='data:image/svg+xml;base64,@card.CardImage.Base64Encode()' alt="Bahncardimage"/>
var from = DateTime.Parse(card.ValidFrom);
var to = DateTime.Parse(card.ValidTo);
var qrfrom = DateTime.Parse(card.QrValidFrom);
var qrto = DateTime.Parse(card.QrValidTo);
if (from > DateTime.Now) {
<div class="alert alert-info" role="alert">
The above card is not valid yet.
</div>
}
if (to < DateTime.Now) {
<div class="alert alert-warning" role="alert">
The above card is expired.
</div>
}
if (qrfrom > DateTime.Now && !(from > DateTime.Now)) {
<div class="alert alert-info" role="alert">
The above QR code is somehow not valid yet. Congrats, please open a bug report.
</div>
}
if (qrto < DateTime.Now) {
<div class="alert alert-warning" role="alert">
The above QR code is expired. Please refresh the card. <a href="/Cards?edit=true">You can do that now</a>.
</div>
}
} }
else { else {
<div class="alert alert-warning" role="alert"> <div class="alert alert-warning" role="alert">
@ -43,6 +69,32 @@ else if (Model.Ticket.TicketInfo.Contains("BC 25")) {
<img src="@card.CardQr" alt="Ticketcode"/> <img src="@card.CardQr" alt="Ticketcode"/>
<img src="@card.CardSecCode" alt="Sichtmerkmal"/> <img src="@card.CardSecCode" alt="Sichtmerkmal"/>
<img style="margin: -50px; height: 450px; transform: rotate(-90deg); position: relative; left: 130px" src='data:image/svg+xml;base64,@card.CardImage.Base64Encode()' alt="Bahncardimage"/> <img style="margin: -50px; height: 450px; transform: rotate(-90deg); position: relative; left: 130px" src='data:image/svg+xml;base64,@card.CardImage.Base64Encode()' alt="Bahncardimage"/>
var from = DateTime.Parse(card.ValidFrom);
var to = DateTime.Parse(card.ValidTo);
var qrfrom = DateTime.Parse(card.QrValidFrom);
var qrto = DateTime.Parse(card.QrValidTo);
if (from > DateTime.Now) {
<div class="alert alert-info" role="alert">
The above card is not valid yet.
</div>
}
if (to < DateTime.Now) {
<div class="alert alert-warning" role="alert">
The above card is expired.
</div>
}
if (qrfrom > DateTime.Now && !(from > DateTime.Now)) {
<div class="alert alert-info" role="alert">
The above QR code is somehow not valid yet. Congrats, please open a bug report.
</div>
}
if (qrto < DateTime.Now) {
<div class="alert alert-warning" role="alert">
The above QR code is expired. Please refresh the card. <a href="/Cards?edit=true">You can do that now</a>.
</div>
}
} }
else { else {
<div class="alert alert-warning" role="alert"> <div class="alert alert-warning" role="alert">

View file

@ -1,4 +1,3 @@
using System.Collections.Generic;
using System.Linq; using System.Linq;
using bahnplan.web.database; using bahnplan.web.database;
using bahnplan.web.database.Tables; using bahnplan.web.database.Tables;
@ -7,16 +6,16 @@ using Microsoft.AspNetCore.Mvc.RazorPages;
namespace bahnplan.web.Pages { namespace bahnplan.web.Pages {
public class InspectionModel : PageModel { public class InspectionModel : PageModel {
public Leg Leg;
public Ticket Ticket; public Ticket Ticket;
public Leg Leg;
public void OnGet() { public void OnGet() {
if (HttpContext.Session.GetString("authorized") != "true") { if (HttpContext.Session.GetString("authorized") != "true")
return; return;
}
using var db = new Database.DbConn(); using var db = new Database.DbConn();
Ticket = db.Tickets.First(p => p.TicketId == int.Parse(Request.Query["id"])); Ticket = db.Tickets.First(p => p.TicketId == int.Parse(Request.Query["id"]));
Leg = db.Legs.First(p => p.LegId == int.Parse(Request.Query["leg"])); Leg = db.Legs.First(p => p.LegId == int.Parse(Request.Query["leg"]));
} }
} }
} }

View file

@ -1,3 +1,4 @@
using System;
using System.Linq; using System.Linq;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Text; using System.Text;
@ -12,8 +13,7 @@ namespace bahnplan.web.Pages {
return; return;
using var db = new Database.DbConn(); using var db = new Database.DbConn();
var user = db.Users.FirstOrDefault(p => p.Username == Request.Form["user"].ToString() var user = db.Users.FirstOrDefault(p => p.Username == Request.Form["user"].ToString() && p.Password == Request.Form["pass"].ToString().Sha256());
&& p.Password == Request.Form["pass"].ToString().Sha256());
if (user == null) if (user == null)
return; return;
@ -24,28 +24,26 @@ namespace bahnplan.web.Pages {
//TODO //TODO
} }
} }
public static class StringExtensions { public static class StringExtensions {
public static string Sha256(this string rawData) { public static string Sha256(this string rawData) {
// Create a SHA256 // Create a SHA256
using var sha256Hash = SHA256.Create(); using var sha256Hash = SHA256.Create();
// ComputeHash - returns byte array // ComputeHash - returns byte array
var bytes = sha256Hash.ComputeHash(Encoding.UTF8.GetBytes(rawData)); var bytes = sha256Hash.ComputeHash(Encoding.UTF8.GetBytes(rawData));
// Convert byte array to a string // Convert byte array to a string
var builder = new StringBuilder(); var builder = new StringBuilder();
for (var i = 0; i < bytes.Length; i++) { for (var i = 0; i < bytes.Length; i++)
builder.Append(bytes[i].ToString("x2")); builder.Append(bytes[i].ToString("x2"));
}
return builder.ToString(); return builder.ToString();
} }
public static string Base64Encode(this string plainText) { public static string Base64Encode(this string plainText) {
var plainTextBytes = Encoding.UTF8.GetBytes(plainText); var plainTextBytes = Encoding.UTF8.GetBytes(plainText);
return System.Convert.ToBase64String(plainTextBytes); return Convert.ToBase64String(plainTextBytes);
} }
} }
} }

View file

@ -4,4 +4,4 @@
@{ @{
Layout = null; Layout = null;
Response.Redirect("/"); Response.Redirect("/");
} }

View file

@ -1,10 +1,3 @@
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using bahnplan.web.database;
using bahnplan.web.database.Tables;
using LinqToDB;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.Mvc.RazorPages;
namespace bahnplan.web.Pages { namespace bahnplan.web.Pages {

View file

@ -3,12 +3,12 @@
@model OEAPIModel @model OEAPIModel
@{ @{
ViewData["Title"] = "OEAPI"; ViewData["Title"] = "OEAPI";
if (HttpContext.Session.GetString("authorized") != "true") { if (HttpContext.Session.GetString("authorized") != "true") {
Response.Redirect("/"); Response.Redirect("/");
return; return;
} }
Response.Redirect("/Trip?id=" + Model.TripId + "&edit=true"); Response.Redirect("/Trip?id=" + Model.TripId + "&edit=true");
} }

View file

@ -1,21 +1,12 @@
using System; using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Linq;
using bahnplan.web.database; using bahnplan.web.database;
using bahnplan.web.database.Tables; using bahnplan.web.database.Tables;
using bahnplan.web.JSON; using bahnplan.web.JSON;
using LinqToDB; using LinqToDB;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Leg = bahnplan.web.database.Tables.Leg; using Leg = bahnplan.web.database.Tables.Leg;
// ReSharper disable PossibleInvalidOperationException // ReSharper disable PossibleInvalidOperationException
@ -25,11 +16,9 @@ namespace bahnplan.web.Pages {
public int TripId; public int TripId;
public void OnGet() { public void OnGet() {
if (HttpContext.Session.GetString("authorized") != "true")
if (HttpContext.Session.GetString("authorized") != "true") {
return; return;
}
var link = Request.Query["link"].ToString(); var link = Request.Query["link"].ToString();
var shortcode = link; var shortcode = link;
if (link.Contains("oeffisear.ch")) if (link.Contains("oeffisear.ch"))
@ -61,7 +50,7 @@ namespace bahnplan.web.Pages {
ArrTime = arrtime.ToString("yyyy-MM-ddTHH:mm:ss"), ArrTime = arrtime.ToString("yyyy-MM-ddTHH:mm:ss"),
DepStation = journey.Departure.Point.Stop.Name, DepStation = journey.Departure.Point.Stop.Name,
DepStationId = int.Parse(journey.Departure.Point.Stop.Id), DepStationId = int.Parse(journey.Departure.Point.Stop.Id),
DepTime = deptime.ToString("yyyy-MM-ddTHH:mm:ss"), DepTime = deptime.ToString("yyyy-MM-ddTHH:mm:ss")
}); });
} }

View file

@ -1,18 +1,11 @@
using System; using Microsoft.AspNetCore.Mvc.RazorPages;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
namespace bahnplan.web.Pages { namespace bahnplan.web.Pages {
public class PrivacyModel : PageModel { public class PrivacyModel : PageModel {
private readonly ILogger<PrivacyModel> _logger; private readonly ILogger<PrivacyModel> _logger;
public PrivacyModel(ILogger<PrivacyModel> logger) { public PrivacyModel(ILogger<PrivacyModel> logger) => _logger = logger;
_logger = logger;
}
public void OnGet() { } public void OnGet() { }
} }

View file

@ -1,6 +1,4 @@
using System.Linq; using System.Linq;
using System.Security.Cryptography;
using System.Text;
using bahnplan.web.database; using bahnplan.web.database;
using bahnplan.web.database.Tables; using bahnplan.web.database.Tables;
using LinqToDB; using LinqToDB;
@ -10,21 +8,21 @@ using Microsoft.AspNetCore.Mvc.RazorPages;
namespace bahnplan.web.Pages { namespace bahnplan.web.Pages {
public class RegisterModel : PageModel { public class RegisterModel : PageModel {
public void OnPost() { public void OnPost() {
if (!Request.HasFormContentType || string.IsNullOrWhiteSpace(Request.Form["user"]) || string.IsNullOrWhiteSpace(Request.Form["pass"]) || string.IsNullOrWhiteSpace(Request.Form["code"])) if (!Request.HasFormContentType
|| string.IsNullOrWhiteSpace(Request.Form["user"])
|| string.IsNullOrWhiteSpace(Request.Form["pass"])
|| string.IsNullOrWhiteSpace(Request.Form["code"]))
return; return;
if (Request.Form["code"] != System.IO.File.ReadAllLines("regkey.txt")[0]) if (Request.Form["code"] != System.IO.File.ReadAllLines("regkey.txt")[0])
return; return;
using var db = new Database.DbConn(); using var db = new Database.DbConn();
var user = db.Users.FirstOrDefault(p => p.Username == Request.Form["user"].ToString()); var user = db.Users.FirstOrDefault(p => p.Username == Request.Form["user"].ToString());
if (user != null) if (user != null)
return; //user already exists return; //user already exists
var uid = db.InsertWithInt32Identity(new User { var uid = db.InsertWithInt32Identity(new User {Username = Request.Form["user"].ToString(), Password = Request.Form["pass"].ToString().Sha256()});
Username = Request.Form["user"].ToString(),
Password = Request.Form["pass"].ToString().Sha256(),
});
HttpContext.Session.SetString("uid", uid.ToString()); HttpContext.Session.SetString("uid", uid.ToString());
HttpContext.Session.SetString("authorized", "true"); HttpContext.Session.SetString("authorized", "true");

View file

@ -65,6 +65,6 @@
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script> <script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<script src="~/js/site.js" asp-append-version="true"></script> <script src="~/js/site.js" asp-append-version="true"></script>
@RenderSection("Scripts", required: false) @RenderSection("Scripts", false)
</body> </body>
</html> </html>

View file

@ -3,12 +3,12 @@
@model TicketModel @model TicketModel
@{ @{
ViewData["Title"] = "Ticket"; ViewData["Title"] = "Ticket";
if (HttpContext.Session.GetString("authorized") != "true") { if (HttpContext.Session.GetString("authorized") != "true") {
Response.Redirect("/"); Response.Redirect("/");
return; return;
} }
Response.Redirect("/Trip?id=" + Model.TripId + "&edit=true"); Response.Redirect("/Trip?id=" + Model.TripId + "&edit=true");
} }

View file

@ -1,9 +1,5 @@
using System; using System.Linq;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net; using System.Net;
using System.Threading.Tasks;
using System.Xml; using System.Xml;
using System.Xml.Linq; using System.Xml.Linq;
using bahnplan.web.database; using bahnplan.web.database;
@ -11,9 +7,7 @@ using bahnplan.web.database.Tables;
using bahnplan.web.JSON; using bahnplan.web.JSON;
using LinqToDB; using LinqToDB;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json; using Newtonsoft.Json;
using Leg = bahnplan.web.database.Tables.Leg; using Leg = bahnplan.web.database.Tables.Leg;
@ -22,11 +16,9 @@ namespace bahnplan.web.Pages {
public int TripId; public int TripId;
public void OnGet() { public void OnGet() {
if (HttpContext.Session.GetString("authorized") != "true") { if (HttpContext.Session.GetString("authorized") != "true")
return; return;
}
using var db = new Database.DbConn(); using var db = new Database.DbConn();
if (db.Tickets.Any(p => p.OrderId == Request.Query["order"].ToString())) { if (db.Tickets.Any(p => p.OrderId == Request.Query["order"].ToString())) {
var tripId = Request.Query["action"] == "addleg" var tripId = Request.Query["action"] == "addleg"
@ -34,7 +26,7 @@ namespace bahnplan.web.Pages {
: db.InsertWithInt32Identity(new Trip {UserId = int.Parse(HttpContext.Session.GetString("uid"))}); : db.InsertWithInt32Identity(new Trip {UserId = int.Parse(HttpContext.Session.GetString("uid"))});
var ticketId = db.Tickets.First(p => p.OrderId == Request.Query["order"].ToString()).TicketId; var ticketId = db.Tickets.First(p => p.OrderId == Request.Query["order"].ToString()).TicketId;
foreach (var leg in db.TicketLegs.Where(p => p.TicketId == ticketId).ToList()) { foreach (var leg in db.TicketLegs.Where(p => p.TicketId == ticketId).ToList())
db.InsertWithInt32Identity(new Leg { db.InsertWithInt32Identity(new Leg {
TripId = tripId, TripId = tripId,
UserId = int.Parse(HttpContext.Session.GetString("uid")), UserId = int.Parse(HttpContext.Session.GetString("uid")),
@ -46,9 +38,8 @@ namespace bahnplan.web.Pages {
DepStation = leg.DepStation, DepStation = leg.DepStation,
DepStationId = leg.DepStationId, DepStationId = leg.DepStationId,
DepTime = leg.DepTime, DepTime = leg.DepTime,
TicketId = ticketId, TicketId = ticketId
}); });
}
TripId = tripId; TripId = tripId;
} }
@ -79,7 +70,7 @@ namespace bahnplan.web.Pages {
TicketPkPass = parsed.Rporderdetails.Order.Tcklist.Tck.Htdata.Ht.First(p => p.Name == "pass").Text, // application/vnd.apple.pkpass;base64 TicketPkPass = parsed.Rporderdetails.Order.Tcklist.Tck.Htdata.Ht.First(p => p.Name == "pass").Text, // application/vnd.apple.pkpass;base64
Traveller = parsed.Rporderdetails.Order.Tcklist.Tck.Mtk.ReisenderVorname Traveller = parsed.Rporderdetails.Order.Tcklist.Tck.Mtk.ReisenderVorname
+ " " + " "
+ parsed.Rporderdetails.Order.Tcklist.Tck.Mtk.ReisenderNachname, + parsed.Rporderdetails.Order.Tcklist.Tck.Mtk.ReisenderNachname
}); });
foreach (var leg in parsed.Rporderdetails.Order.Schedulelist.Out.Trainlist.Train) { foreach (var leg in parsed.Rporderdetails.Order.Schedulelist.Out.Trainlist.Train) {
@ -94,7 +85,7 @@ namespace bahnplan.web.Pages {
DepStation = leg.Dep.Name, DepStation = leg.Dep.Name,
DepStationId = int.Parse(leg.Dep.BhfNr), DepStationId = int.Parse(leg.Dep.BhfNr),
DepTime = leg.Dep.Date.Replace("00:00:00", leg.Dep.Time), DepTime = leg.Dep.Date.Replace("00:00:00", leg.Dep.Time),
TicketId = ticketId, TicketId = ticketId
}); });
db.InsertWithInt32Identity(new TicketLeg { db.InsertWithInt32Identity(new TicketLeg {
@ -106,7 +97,7 @@ namespace bahnplan.web.Pages {
ArrTime = leg.Arr.Date.Replace("00:00:00", leg.Arr.Time), ArrTime = leg.Arr.Date.Replace("00:00:00", leg.Arr.Time),
DepStation = leg.Dep.Name, DepStation = leg.Dep.Name,
DepStationId = int.Parse(leg.Dep.BhfNr), DepStationId = int.Parse(leg.Dep.BhfNr),
DepTime = leg.Dep.Date.Replace("00:00:00", leg.Dep.Time), DepTime = leg.Dep.Date.Replace("00:00:00", leg.Dep.Time)
}); });
} }

View file

@ -1,10 +1,10 @@
@page @page
@using bahnplan.web.database
@using Microsoft.AspNetCore.Http @using Microsoft.AspNetCore.Http
@using bahnplan.web.database
@model TripModel @model TripModel
@{ @{
ViewData["Title"] = "Trip"; ViewData["Title"] = "Trip";
if (HttpContext.Session.GetString("authorized") != "true") { if (HttpContext.Session.GetString("authorized") != "true") {
Response.Redirect("/"); Response.Redirect("/");
return; return;
@ -107,8 +107,8 @@
else { else {
<a class="btn btn-sm btn-danger disabled">Ticket</a> <a class="btn btn-sm btn-danger disabled">Ticket</a>
} }
<a class="btn btn-sm btn-primary" href="https://marudor.de/details/@leg.TrainType @leg.TrainNr/@(deptime.ToUniversalTime().Subtract(new DateTime(1970, 1, 1)).TotalSeconds)000/?station=@leg.DepStationId">Marudor</a> <a class="btn btn-sm btn-primary" href="https://marudor.de/details/@leg.TrainType @leg.TrainNr/@(deptime.ToUniversalTime().Subtract(new DateTime(1970, 1, 1)).TotalSeconds)000/?station=@leg.DepStationId" target="_blank">Marudor</a>
<a class="btn btn-sm btn-warning" href="https://travelynx.de/s/@leg.DepStationId?train=@leg.TrainType @leg.TrainNr">Travelynx</a> <a class="btn btn-sm btn-warning" href="https://travelynx.de/s/@leg.DepStationId?train=@leg.TrainType @leg.TrainNr" target="_blank">Travelynx</a>
</td> </td>
} }
else { else {

View file

@ -11,9 +11,8 @@ namespace bahnplan.web.Pages {
public List<Leg> Legs; public List<Leg> Legs;
public void OnGet() { public void OnGet() {
if (HttpContext.Session.GetString("authorized") != "true") { if (HttpContext.Session.GetString("authorized") != "true")
return; return;
}
using var db = new Database.DbConn(); using var db = new Database.DbConn();
if (Request.Query.ContainsKey("separator")) { if (Request.Query.ContainsKey("separator")) {
@ -28,7 +27,7 @@ namespace bahnplan.web.Pages {
ArrTime = "_", ArrTime = "_",
DepStation = "_", DepStation = "_",
DepStationId = 0, DepStationId = 0,
DepTime = leg.DepTime + "_placeholder", DepTime = leg.DepTime + "_placeholder"
}); });
return; return;
} }

View file

@ -1,20 +1,15 @@
using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
using System.Threading.Tasks;
using bahnplan.web.database; using bahnplan.web.database;
using LinqToDB.Common;
using LinqToDB.Data; using LinqToDB.Data;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
namespace bahnplan.web { namespace bahnplan.web {
public class Program { public class Program {
public static void Main(string[] args) { public static void Main(string[] args) {
DataConnection.DefaultSettings = new Database.Settings(); DataConnection.DefaultSettings = new Database.Settings();
LinqToDB.Common.Configuration.Linq.AllowMultipleQuery = true; Configuration.Linq.AllowMultipleQuery = true;
Directory.CreateDirectory(Variables.TicketDir); Directory.CreateDirectory(Variables.TicketDir);
CreateHostBuilder(args).Build().Run(); CreateHostBuilder(args).Build().Run();
} }

View file

@ -1,20 +1,13 @@
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
namespace bahnplan.web { namespace bahnplan.web {
public class Startup { public class Startup {
public Startup(IConfiguration configuration) { public Startup(IConfiguration configuration) => Configuration = configuration;
Configuration = configuration;
}
public IConfiguration Configuration { get; } public IConfiguration Configuration { get; }

View file

@ -1,4 +1,3 @@
using System;
using System.IO; using System.IO;
namespace bahnplan.web { namespace bahnplan.web {

View file

@ -3,6 +3,7 @@ using System.Linq;
using bahnplan.web.database.Tables; using bahnplan.web.database.Tables;
using LinqToDB; using LinqToDB;
using LinqToDB.Configuration; using LinqToDB.Configuration;
using LinqToDB.Data;
namespace bahnplan.web.database { namespace bahnplan.web.database {
public class Database { public class Database {
@ -24,15 +25,15 @@ namespace bahnplan.web.database {
} }
} }
public class DbConn : LinqToDB.Data.DataConnection { public class DbConn : DataConnection {
public DbConn() : base("db") { } public DbConn() : base("db") { }
public ITable<User> Users => GetTable<User>(); public ITable<User> Users => GetTable<User>();
public ITable<Leg> Legs => GetTable<Leg>(); public ITable<Leg> Legs => GetTable<Leg>();
public ITable<Ticket> Tickets => GetTable<Ticket>(); public ITable<Ticket> Tickets => GetTable<Ticket>();
public ITable<TicketLeg> TicketLegs => GetTable<TicketLeg>(); public ITable<TicketLeg> TicketLegs => GetTable<TicketLeg>();
public ITable<Trip> Trips => GetTable<Trip>(); public ITable<Trip> Trips => GetTable<Trip>();
public ITable<Card> Cards => GetTable<Card>(); public ITable<Card> Cards => GetTable<Card>();
} }
} }
} }

View file

@ -5,47 +5,33 @@ namespace bahnplan.web.database.Tables {
public class Card { public class Card {
[Column(Name = "CardID"), PrimaryKey, Identity, NotNull] [Column(Name = "CardID"), PrimaryKey, Identity, NotNull]
public int CardId { get; set; } public int CardId { get; set; }
[Column(Name = "OrderID"), NotNull]
public string OrderId { get; set; }
[Column(Name = "UserID"), NotNull] [Column(Name = "OrderID"), NotNull] public string OrderId { get; set; }
public int UserId { get; set; }
[Column(Name = "CardNumber"), NotNull]
public string CardNumber { get; set; }
[Column(Name = "Class"), NotNull] [Column(Name = "UserID"), NotNull] public int UserId { get; set; }
public int Class { get; set; }
[Column(Name = "Value"), NotNull]
public int Value { get; set; }
[Column(Name = "Traveller")]
public string Traveller { get; set; }
[Column(Name = "CardQR")]
public string CardQr { get; set; }
[Column(Name = "CardSecCode")]
public string CardSecCode { get; set; }
[Column(Name = "CardImage")]
public string CardImage { get; set; }
[Column(Name = "CardInfo")]
public string CardInfo { get; set; }
[Column(Name = "ValidFrom")] [Column(Name = "CardNumber"), NotNull] public string CardNumber { get; set; }
public string ValidFrom { get; set; }
[Column(Name = "Class"), NotNull] public int Class { get; set; }
[Column(Name = "ValidTo")]
public string ValidTo { get; set; } [Column(Name = "Value"), NotNull] public int Value { get; set; }
[Column(Name = "QRValidFrom")] [Column(Name = "Traveller")] public string Traveller { get; set; }
public string QrValidFrom { get; set; }
[Column(Name = "CardQR")] public string CardQr { get; set; }
[Column(Name = "QRValidTo")]
public string QrValidTo { get; set; } [Column(Name = "CardSecCode")] public string CardSecCode { get; set; }
[Column(Name = "CardImage")] public string CardImage { get; set; }
[Column(Name = "CardInfo")] public string CardInfo { get; set; }
[Column(Name = "ValidFrom")] public string ValidFrom { get; set; }
[Column(Name = "ValidTo")] public string ValidTo { get; set; }
[Column(Name = "QRValidFrom")] public string QrValidFrom { get; set; }
[Column(Name = "QRValidTo")] public string QrValidTo { get; set; }
} }
} }

View file

@ -5,38 +5,29 @@ namespace bahnplan.web.database.Tables {
public class Leg { public class Leg {
[Column(Name = "LegID"), PrimaryKey, Identity, NotNull] [Column(Name = "LegID"), PrimaryKey, Identity, NotNull]
public int LegId { get; set; } public int LegId { get; set; }
[Column(Name = "TripID"), NotNull]
public int TripId { get; set; }
[Column(Name = "UserID"), NotNull] [Column(Name = "TripID"), NotNull] public int TripId { get; set; }
public int UserId { get; set; }
[Column(Name = "UserID"), NotNull] public int UserId { get; set; }
[Column(Name = "TrainType"), NotNull] public string TrainType { get; set; }
[Column(Name = "TrainNr"), NotNull] public int TrainNr { get; set; }
[Column(Name = "TrainType"), NotNull]
public string TrainType { get; set; }
[Column(Name = "TrainNr"), NotNull]
public int TrainNr { get; set; }
[Column(Name = "DepStationID"), NotNull] [Column(Name = "DepStationID"), NotNull]
public int DepStationId { get; set; } public int DepStationId { get; set; }
[Column(Name = "DepStation"), NotNull]
public string DepStation { get; set; }
[Column(Name = "DepTime"), NotNull] [Column(Name = "DepStation"), NotNull] public string DepStation { get; set; }
public string DepTime { get; set; }
[Column(Name = "DepTime"), NotNull] public string DepTime { get; set; }
[Column(Name = "ArrStationID"), NotNull] [Column(Name = "ArrStationID"), NotNull]
public int ArrStationId { get; set; } public int ArrStationId { get; set; }
[Column(Name = "ArrStation"), NotNull] [Column(Name = "ArrStation"), NotNull] public string ArrStation { get; set; }
public string ArrStation { get; set; }
[Column(Name = "ArrTime"), NotNull] [Column(Name = "ArrTime"), NotNull] public string ArrTime { get; set; }
public string ArrTime { get; set; }
[Column(Name = "TicketID")] public int TicketId { get; set; }
[Column(Name = "TicketID")]
public int TicketId { get; set; }
} }
} }

View file

@ -5,26 +5,21 @@ namespace bahnplan.web.database.Tables {
public class Ticket { public class Ticket {
[Column(Name = "TicketID"), PrimaryKey, Identity, NotNull] [Column(Name = "TicketID"), PrimaryKey, Identity, NotNull]
public int TicketId { get; set; } public int TicketId { get; set; }
[Column(Name = "OrderID"), NotNull]
public string OrderId { get; set; }
[Column(Name = "UserID"), NotNull] [Column(Name = "OrderID"), NotNull] public string OrderId { get; set; }
public int UserId { get; set; }
[Column(Name = "UserID"), NotNull] public int UserId { get; set; }
[Column(Name = "TicketInfo"), NotNull]
public string TicketInfo { get; set; } [Column(Name = "TicketInfo"), NotNull] public string TicketInfo { get; set; }
[Column(Name = "TicketQR"), NotNull] [Column(Name = "TicketQR"), NotNull] public string TicketQr { get; set; }
public string TicketQr { get; set; }
[Column(Name = "TicketSecCode"), NotNull] [Column(Name = "TicketSecCode"), NotNull]
public string TicketSecCode { get; set; } public string TicketSecCode { get; set; }
[Column(Name = "TicketPkPass"), NotNull] [Column(Name = "TicketPkPass"), NotNull]
public string TicketPkPass { get; set; } public string TicketPkPass { get; set; }
[Column(Name = "Traveller")] [Column(Name = "Traveller")] public string Traveller { get; set; }
public string Traveller { get; set; }
} }
} }

View file

@ -5,32 +5,25 @@ namespace bahnplan.web.database.Tables {
public class TicketLeg { public class TicketLeg {
[Column(Name = "TicketLegID"), PrimaryKey, Identity, NotNull] [Column(Name = "TicketLegID"), PrimaryKey, Identity, NotNull]
public int TicketLegId { get; set; } public int TicketLegId { get; set; }
[Column(Name = "TicketID"), NotNull]
public int TicketId { get; set; }
[Column(Name = "TrainType"), NotNull] [Column(Name = "TicketID"), NotNull] public int TicketId { get; set; }
public string TrainType { get; set; }
[Column(Name = "TrainType"), NotNull] public string TrainType { get; set; }
[Column(Name = "TrainNr"), NotNull]
public int TrainNr { get; set; } [Column(Name = "TrainNr"), NotNull] public int TrainNr { get; set; }
[Column(Name = "DepStationID"), NotNull] [Column(Name = "DepStationID"), NotNull]
public int DepStationId { get; set; } public int DepStationId { get; set; }
[Column(Name = "DepStation"), NotNull]
public string DepStation { get; set; }
[Column(Name = "DepTime"), NotNull] [Column(Name = "DepStation"), NotNull] public string DepStation { get; set; }
public string DepTime { get; set; }
[Column(Name = "DepTime"), NotNull] public string DepTime { get; set; }
[Column(Name = "ArrStationID"), NotNull] [Column(Name = "ArrStationID"), NotNull]
public int ArrStationId { get; set; } public int ArrStationId { get; set; }
[Column(Name = "ArrStation"), NotNull] [Column(Name = "ArrStation"), NotNull] public string ArrStation { get; set; }
public string ArrStation { get; set; }
[Column(Name = "ArrTime"), NotNull] [Column(Name = "ArrTime"), NotNull] public string ArrTime { get; set; }
public string ArrTime { get; set; }
} }
} }

View file

@ -1,10 +1,9 @@
using LinqToDB.Mapping; using LinqToDB.Mapping;
namespace bahnplan.web.database.Tables { namespace bahnplan.web.database.Tables {
[Table(Name = "Trips")] [Table(Name = "Trips")]
public class Trip { public class Trip {
[Column(Name = "TripID"), PrimaryKey, Identity, NotNull] [Column(Name = "TripID"), PrimaryKey, Identity, NotNull]
public int TripId { get; set; } public int TripId { get; set; }
[Column(Name = "UserID"), PrimaryKey, NotNull] [Column(Name = "UserID"), PrimaryKey, NotNull]

View file

@ -1,4 +1,3 @@
using System;
using LinqToDB.Mapping; using LinqToDB.Mapping;
namespace bahnplan.web.database.Tables { namespace bahnplan.web.database.Tables {
@ -7,10 +6,8 @@ namespace bahnplan.web.database.Tables {
[Column(Name = "UserID"), PrimaryKey, Identity, NotNull] [Column(Name = "UserID"), PrimaryKey, Identity, NotNull]
public int UserId { get; set; } public int UserId { get; set; }
[Column(Name = "Username"), NotNull] [Column(Name = "Username"), NotNull] public string Username { get; set; }
public string Username { get; set; }
[Column(Name = "Password"), NotNull] public string Password { get; set; }
[Column(Name = "Password"), NotNull]
public string Password { get; set; }
} }
} }

View file

@ -5303,7 +5303,7 @@
for (var i = 0, len = elements.length; i < len; i++) { for (var i = 0, len = elements.length; i < len; i++) {
var _ret = _loop(i, len); var _ret = _loop(i, len);
if (_ret === "continue") continue; if (_ret === "continue")
} }
return createdDocument.body.innerHTML; return createdDocument.body.innerHTML;

View file

@ -2725,7 +2725,7 @@
for (var i = 0, len = elements.length; i < len; i++) { for (var i = 0, len = elements.length; i < len; i++) {
var _ret = _loop(i, len); var _ret = _loop(i, len);
if (_ret === "continue") continue; if (_ret === "continue")
} }
return createdDocument.body.innerHTML; return createdDocument.body.innerHTML;

View file

@ -322,7 +322,7 @@ $.extend( $.validator, {
]; ];
if ( event.which === 9 && this.elementValue( element ) === "" || $.inArray( event.keyCode, excludedKeys ) !== -1 ) { if ( event.which === 9 && this.elementValue( element ) === "" || $.inArray( event.keyCode, excludedKeys ) !== -1 ) {
return;
} else if ( element.name in this.submitted || element.name in this.invalid ) { } else if ( element.name in this.submitted || element.name in this.invalid ) {
this.element( element ); this.element( element );
} }

View file

@ -2804,7 +2804,7 @@ function nodeName( elem, name ) {
return elem.nodeName && elem.nodeName.toLowerCase() === name.toLowerCase(); return elem.nodeName && elem.nodeName.toLowerCase() === name.toLowerCase();
}; }
var rsingleTag = ( /^<([a-z][^\/\0>:\x20\t\r\n\f]*)[\x20\t\r\n\f]*\/?>(?:<\/\1>|)$/i ); var rsingleTag = ( /^<([a-z][^\/\0>:\x20\t\r\n\f]*)[\x20\t\r\n\f]*\/?>(?:<\/\1>|)$/i );