From b443f2125be333ff4e29ba5f1a736e87c29cd107 Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Mon, 15 Jun 2020 02:52:44 +0200 Subject: [PATCH] fix oeffisearch; add support for return tickets --- bahnplan.web/JSON/TicketResponse.cs | 17 ++++++++++------- bahnplan.web/Pages/OEAPI.cshtml.cs | 2 +- bahnplan.web/Pages/Ticket.cshtml.cs | 29 +++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 8 deletions(-) diff --git a/bahnplan.web/JSON/TicketResponse.cs b/bahnplan.web/JSON/TicketResponse.cs index 685020d..1468b40 100644 --- a/bahnplan.web/JSON/TicketResponse.cs +++ b/bahnplan.web/JSON/TicketResponse.cs @@ -94,12 +94,12 @@ namespace bahnplan.web.JSON { } public class Posinfolist { - [J("posinfo", NullValueHandling = NV.Ignore)] - public PosinfoElement Posinfo { get; set; } + [J("posinfo", NullValueHandling = NV.Ignore), JsonConverter(typeof(SingleOrArrayConverter))] + public List Posinfo { get; set; } } public class FluffyChildlist { - [J("posinfo", NullValueHandling = NV.Ignore)] + [J("posinfo", NullValueHandling = NV.Ignore), JsonConverter(typeof(SingleOrArrayConverter))] public List Posinfo { get; set; } } @@ -136,8 +136,8 @@ namespace bahnplan.web.JSON { } public class PurpleChildlist { - [J("posinfo", NullValueHandling = NV.Ignore)] - public PurplePosinfo Posinfo { get; set; } + [J("posinfo", NullValueHandling = NV.Ignore), JsonConverter(typeof(SingleOrArrayConverter))] + public List Posinfo { get; set; } } public class PosinfoElement { @@ -231,10 +231,13 @@ namespace bahnplan.web.JSON { public class Schedulelist { [J("out", NullValueHandling = NV.Ignore)] - public Out Out { get; set; } + public Journey Out { get; set; } + + [J("ret", NullValueHandling = NV.Ignore)] + public Journey Ret { get; set; } } - public class Out { + public class Journey { [J("txt", NullValueHandling = NV.Ignore)] public string Txt { get; set; } diff --git a/bahnplan.web/Pages/OEAPI.cshtml.cs b/bahnplan.web/Pages/OEAPI.cshtml.cs index b398c0f..b042cb5 100644 --- a/bahnplan.web/Pages/OEAPI.cshtml.cs +++ b/bahnplan.web/Pages/OEAPI.cshtml.cs @@ -39,7 +39,7 @@ namespace bahnplan.web.Pages { ? int.Parse(Request.Query["tripid"]) : db.InsertWithInt32Identity(new Trip {UserId = int.Parse(HttpContext.Session.GetString("uid"))}); - foreach (var journey in parsed.Data.Journeys[jid].Legs) { + foreach (var journey in parsed.Data.Journeys[jid].Legs.Where(p => p.IsTransfer != true && p.IsWalking != true)) { var arrtime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc); var deptime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc); arrtime = arrtime.AddSeconds((long) journey.Arrival.PlannedTime).ToLocalTime(); diff --git a/bahnplan.web/Pages/Ticket.cshtml.cs b/bahnplan.web/Pages/Ticket.cshtml.cs index 666c32f..983cfdb 100644 --- a/bahnplan.web/Pages/Ticket.cshtml.cs +++ b/bahnplan.web/Pages/Ticket.cshtml.cs @@ -105,6 +105,35 @@ namespace bahnplan.web.Pages { }); } + if (parsed.Rporderdetails.Order.Schedulelist.Ret != null) + foreach (var leg in parsed.Rporderdetails.Order.Schedulelist.Ret.Trainlist.Train) { + db.InsertWithInt32Identity(new Leg { + TripId = tripId, + UserId = int.Parse(HttpContext.Session.GetString("uid")), + TrainType = leg.Gattung, + TrainNr = int.Parse(leg.Zugnummer), + ArrStation = leg.Arr.Name, + ArrStationId = int.Parse(leg.Arr.BhfNr), + ArrTime = leg.Arr.Date.Replace("00:00:00", leg.Arr.Time), + DepStation = leg.Dep.Name, + DepStationId = int.Parse(leg.Dep.BhfNr), + DepTime = leg.Dep.Date.Replace("00:00:00", leg.Dep.Time), + TicketId = ticketId + }); + + db.InsertWithInt32Identity(new TicketLeg { + TicketId = ticketId, + TrainType = leg.Gattung, + TrainNr = int.Parse(leg.Zugnummer), + ArrStation = leg.Arr.Name, + ArrStationId = int.Parse(leg.Arr.BhfNr), + ArrTime = leg.Arr.Date.Replace("00:00:00", leg.Arr.Time), + DepStation = leg.Dep.Name, + DepStationId = int.Parse(leg.Dep.BhfNr), + DepTime = leg.Dep.Date.Replace("00:00:00", leg.Dep.Time) + }); + } + TripId = tripId; } }