diff --git a/bahnplan.web/JSON/TicketResponse.cs b/bahnplan.web/JSON/TicketResponse.cs index 1468b40..d2f8ddc 100644 --- a/bahnplan.web/JSON/TicketResponse.cs +++ b/bahnplan.web/JSON/TicketResponse.cs @@ -312,8 +312,8 @@ namespace bahnplan.web.JSON { } public class Tcklist { - [J("tck", NullValueHandling = NV.Ignore)] - public Tck Tck { get; set; } + [J("tck", NullValueHandling = NV.Ignore), JsonConverter(typeof(SingleOrArrayConverter))] + public List Tck { get; set; } } public class Tck { diff --git a/bahnplan.web/Pages/Ticket.cshtml.cs b/bahnplan.web/Pages/Ticket.cshtml.cs index 983cfdb..4ccb6b0 100644 --- a/bahnplan.web/Pages/Ticket.cshtml.cs +++ b/bahnplan.web/Pages/Ticket.cshtml.cs @@ -1,4 +1,5 @@ -using System.Linq; +using System; +using System.Linq; using System.Net; using System.Xml; using System.Xml.Linq; @@ -29,6 +30,7 @@ namespace bahnplan.web.Pages { ? int.Parse(Request.Query["tripid"]) : 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 ticketId2 = db.Tickets.FirstOrDefault(p => p.OrderId == Request.Query["order"].ToString() + "_2")?.TicketId; foreach (var leg in db.TicketLegs.Where(p => p.TicketId == ticketId).ToList()) db.InsertWithInt32Identity(new Leg { @@ -42,8 +44,25 @@ namespace bahnplan.web.Pages { DepStation = leg.DepStation, DepStationId = leg.DepStationId, DepTime = leg.DepTime, - TicketId = ticketId + TicketId = leg.TicketId }); + + if (ticketId2 != null) { + foreach (var leg in db.TicketLegs.Where(p => p.TicketId == ticketId2).ToList()) + db.InsertWithInt32Identity(new Leg { + TripId = tripId, + UserId = int.Parse(HttpContext.Session.GetString("uid")), + TrainType = leg.TrainType, + TrainNr = leg.TrainNr, + ArrStation = leg.ArrStation, + ArrStationId = leg.ArrStationId, + ArrTime = leg.ArrTime, + DepStation = leg.DepStation, + DepStationId = leg.DepStationId, + DepTime = leg.DepTime, + TicketId = leg.TicketId + }); + } TripId = tripId; } @@ -65,17 +84,55 @@ namespace bahnplan.web.Pages { ? int.Parse(Request.Query["tripid"]) : db.InsertWithInt32Identity(new Trip {UserId = int.Parse(HttpContext.Session.GetString("uid"))}); - var ticketId = db.InsertWithInt32Identity(new Ticket { - OrderId = Request.Query["order"], - TicketInfo = parsed.Rporderdetails.Order.Tcklist.Tck.Mtk.Txt, - TicketQr = parsed.Rporderdetails.Order.Tcklist.Tck.Htdata.Ht.First(p => p.Name == "barcode").Text, - TicketSecCode = parsed.Rporderdetails.Order.Tcklist.Tck.Htdata.Ht.First(p => p.Name == "sichtmerkmal").Text, - UserId = int.Parse(HttpContext.Session.GetString("uid")), - 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 - + " " - + parsed.Rporderdetails.Order.Tcklist.Tck.Mtk.ReisenderNachname - }); + int ticketId; + int? ticketId2 = null; + + switch (parsed.Rporderdetails.Order.Tcklist.Tck.Count) { + case 1: { + ticketId = db.InsertWithInt32Identity(new Ticket { + OrderId = Request.Query["order"], + TicketInfo = parsed.Rporderdetails.Order.Tcklist.Tck[0].Mtk.Txt, + TicketQr = parsed.Rporderdetails.Order.Tcklist.Tck[0].Htdata.Ht.First(p => p.Name == "barcode").Text, + TicketSecCode = parsed.Rporderdetails.Order.Tcklist.Tck[0].Htdata.Ht.First(p => p.Name == "sichtmerkmal").Text, + UserId = int.Parse(HttpContext.Session.GetString("uid")), + TicketPkPass = parsed.Rporderdetails.Order.Tcklist.Tck[0].Htdata.Ht.First(p => p.Name == "pass").Text, // application/vnd.apple.pkpass;base64 + Traveller = parsed.Rporderdetails.Order.Tcklist.Tck[0].Mtk.ReisenderVorname + + " " + + parsed.Rporderdetails.Order.Tcklist.Tck[0].Mtk.ReisenderNachname + }); + break; + } + case 2: { + ticketId = db.InsertWithInt32Identity(new Ticket { + OrderId = Request.Query["order"], + TicketInfo = parsed.Rporderdetails.Order.Tcklist.Tck[0].Mtk.Txt, + TicketQr = parsed.Rporderdetails.Order.Tcklist.Tck[0].Htdata.Ht.First(p => p.Name == "barcode").Text, + TicketSecCode = parsed.Rporderdetails.Order.Tcklist.Tck[0].Htdata.Ht.First(p => p.Name == "sichtmerkmal").Text, + UserId = int.Parse(HttpContext.Session.GetString("uid")), + TicketPkPass = parsed.Rporderdetails.Order.Tcklist.Tck[0].Htdata.Ht.First(p => p.Name == "pass").Text, // application/vnd.apple.pkpass;base64 + Traveller = parsed.Rporderdetails.Order.Tcklist.Tck[0].Mtk.ReisenderVorname + + " " + + parsed.Rporderdetails.Order.Tcklist.Tck[0].Mtk.ReisenderNachname + }); + + ticketId2 = db.InsertWithInt32Identity(new Ticket { + OrderId = Request.Query["order"] + "_2", + TicketInfo = parsed.Rporderdetails.Order.Tcklist.Tck[1].Mtk.Txt, + TicketQr = parsed.Rporderdetails.Order.Tcklist.Tck[1].Htdata.Ht.First(p => p.Name == "barcode").Text, + TicketSecCode = parsed.Rporderdetails.Order.Tcklist.Tck[1].Htdata.Ht.First(p => p.Name == "sichtmerkmal").Text, + UserId = int.Parse(HttpContext.Session.GetString("uid")), + TicketPkPass = parsed.Rporderdetails.Order.Tcklist.Tck[1].Htdata.Ht.First(p => p.Name == "pass").Text, // application/vnd.apple.pkpass;base64 + Traveller = parsed.Rporderdetails.Order.Tcklist.Tck[1].Mtk.ReisenderVorname + + " " + + parsed.Rporderdetails.Order.Tcklist.Tck[1].Mtk.ReisenderNachname + }); + + break; + } + default: { + throw new Exception("Order contains zero or more than two tickets"); + } + } foreach (var leg in parsed.Rporderdetails.Order.Schedulelist.Out.Trainlist.Train) { db.InsertWithInt32Identity(new Leg { @@ -118,11 +175,11 @@ namespace bahnplan.web.Pages { DepStation = leg.Dep.Name, DepStationId = int.Parse(leg.Dep.BhfNr), DepTime = leg.Dep.Date.Replace("00:00:00", leg.Dep.Time), - TicketId = ticketId + TicketId = ticketId2 ?? ticketId }); db.InsertWithInt32Identity(new TicketLeg { - TicketId = ticketId, + TicketId = ticketId2 ?? ticketId, TrainType = leg.Gattung, TrainNr = int.Parse(leg.Zugnummer), ArrStation = leg.Arr.Name,