Fix multi-ticket return trips
This commit is contained in:
parent
166283ca1f
commit
9c495e159f
|
@ -312,8 +312,8 @@ namespace bahnplan.web.JSON {
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Tcklist {
|
public class Tcklist {
|
||||||
[J("tck", NullValueHandling = NV.Ignore)]
|
[J("tck", NullValueHandling = NV.Ignore), JsonConverter(typeof(SingleOrArrayConverter<Tck>))]
|
||||||
public Tck Tck { get; set; }
|
public List<Tck> Tck { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Tck {
|
public class Tck {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System.Linq;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
|
@ -29,6 +30,7 @@ namespace bahnplan.web.Pages {
|
||||||
? int.Parse(Request.Query["tripid"])
|
? int.Parse(Request.Query["tripid"])
|
||||||
: 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;
|
||||||
|
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())
|
foreach (var leg in db.TicketLegs.Where(p => p.TicketId == ticketId).ToList())
|
||||||
db.InsertWithInt32Identity(new Leg {
|
db.InsertWithInt32Identity(new Leg {
|
||||||
|
@ -42,9 +44,26 @@ 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 = 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;
|
TripId = tripId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,17 +84,55 @@ namespace bahnplan.web.Pages {
|
||||||
? int.Parse(Request.Query["tripid"])
|
? int.Parse(Request.Query["tripid"])
|
||||||
: 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.InsertWithInt32Identity(new Ticket {
|
int ticketId;
|
||||||
|
int? ticketId2 = null;
|
||||||
|
|
||||||
|
switch (parsed.Rporderdetails.Order.Tcklist.Tck.Count) {
|
||||||
|
case 1: {
|
||||||
|
ticketId = db.InsertWithInt32Identity(new Ticket {
|
||||||
OrderId = Request.Query["order"],
|
OrderId = Request.Query["order"],
|
||||||
TicketInfo = parsed.Rporderdetails.Order.Tcklist.Tck.Mtk.Txt,
|
TicketInfo = parsed.Rporderdetails.Order.Tcklist.Tck[0].Mtk.Txt,
|
||||||
TicketQr = parsed.Rporderdetails.Order.Tcklist.Tck.Htdata.Ht.First(p => p.Name == "barcode").Text,
|
TicketQr = parsed.Rporderdetails.Order.Tcklist.Tck[0].Htdata.Ht.First(p => p.Name == "barcode").Text,
|
||||||
TicketSecCode = parsed.Rporderdetails.Order.Tcklist.Tck.Htdata.Ht.First(p => p.Name == "sichtmerkmal").Text,
|
TicketSecCode = parsed.Rporderdetails.Order.Tcklist.Tck[0].Htdata.Ht.First(p => p.Name == "sichtmerkmal").Text,
|
||||||
UserId = int.Parse(HttpContext.Session.GetString("uid")),
|
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
|
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.Mtk.ReisenderVorname
|
Traveller = parsed.Rporderdetails.Order.Tcklist.Tck[0].Mtk.ReisenderVorname
|
||||||
+ " "
|
+ " "
|
||||||
+ parsed.Rporderdetails.Order.Tcklist.Tck.Mtk.ReisenderNachname
|
+ 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) {
|
foreach (var leg in parsed.Rporderdetails.Order.Schedulelist.Out.Trainlist.Train) {
|
||||||
db.InsertWithInt32Identity(new Leg {
|
db.InsertWithInt32Identity(new Leg {
|
||||||
|
@ -118,11 +175,11 @@ 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 = ticketId2 ?? ticketId
|
||||||
});
|
});
|
||||||
|
|
||||||
db.InsertWithInt32Identity(new TicketLeg {
|
db.InsertWithInt32Identity(new TicketLeg {
|
||||||
TicketId = ticketId,
|
TicketId = ticketId2 ?? ticketId,
|
||||||
TrainType = leg.Gattung,
|
TrainType = leg.Gattung,
|
||||||
TrainNr = int.Parse(leg.Zugnummer),
|
TrainNr = int.Parse(leg.Zugnummer),
|
||||||
ArrStation = leg.Arr.Name,
|
ArrStation = leg.Arr.Name,
|
||||||
|
|
Reference in a new issue