Automatically create separators on ticket add
This commit is contained in:
parent
e4e54d0341
commit
0457d7c591
|
@ -12,7 +12,8 @@ using Microsoft.AspNetCore.Mvc.RazorPages;
|
|||
using Newtonsoft.Json;
|
||||
using Leg = bahnplan.web.database.Tables.Leg;
|
||||
|
||||
namespace bahnplan.web.Pages {
|
||||
namespace bahnplan.web.Pages;
|
||||
|
||||
public class TicketModel : PageModel {
|
||||
public int TripId;
|
||||
|
||||
|
@ -32,8 +33,25 @@ namespace bahnplan.web.Pages {
|
|||
var ticketId = db.Tickets.First(p => p.OrderId == Request.Query["order"].ToString()).TicketId;
|
||||
var ticketId2 = db.Tickets.FirstOrDefault(p => p.OrderId == Request.Query["order"] + "_2")?.TicketId;
|
||||
|
||||
foreach (var leg in db.TicketLegs.Where(p => p.TicketId == ticketId).ToList())
|
||||
db.InsertWithInt32Identity(new Leg {
|
||||
var lastleg_ticket = 0;
|
||||
foreach (var leg in db.TicketLegs.Where(p => p.TicketId == ticketId).ToList()) {
|
||||
if (leg.TrainType == "placeholder") {
|
||||
db.Insert(new Leg {
|
||||
TripId = tripId,
|
||||
UserId = int.Parse(HttpContext.Session.GetString("uid")),
|
||||
TrainType = "placeholder",
|
||||
TrainNr = lastleg_ticket,
|
||||
ArrStation = "_",
|
||||
ArrStationId = 0,
|
||||
ArrTime = "_",
|
||||
DepStation = "_",
|
||||
DepStationId = 0,
|
||||
DepTime = db.Legs.First(p => p.LegId == lastleg_ticket).DepTime + "_placeholder"
|
||||
});
|
||||
continue;
|
||||
}
|
||||
|
||||
lastleg_ticket = db.InsertWithInt32Identity(new Leg {
|
||||
TripId = tripId,
|
||||
UserId = int.Parse(HttpContext.Session.GetString("uid")),
|
||||
TrainType = leg.TrainType,
|
||||
|
@ -46,8 +64,11 @@ namespace bahnplan.web.Pages {
|
|||
DepTime = leg.DepTime,
|
||||
TicketId = leg.TicketId
|
||||
});
|
||||
}
|
||||
|
||||
if (ticketId2 != null) {
|
||||
var lastleg = 0;
|
||||
|
||||
if (ticketId2 != null)
|
||||
foreach (var leg in db.TicketLegs.Where(p => p.TicketId == ticketId2).ToList())
|
||||
db.InsertWithInt32Identity(new Leg {
|
||||
TripId = tripId,
|
||||
|
@ -62,6 +83,7 @@ namespace bahnplan.web.Pages {
|
|||
DepTime = leg.DepTime,
|
||||
TicketId = leg.TicketId
|
||||
});
|
||||
}
|
||||
|
||||
TripId = tripId;
|
||||
}
|
||||
|
@ -141,8 +163,11 @@ namespace bahnplan.web.Pages {
|
|||
}
|
||||
}
|
||||
|
||||
var lastleg = 0;
|
||||
var lastticketleg = 0;
|
||||
|
||||
foreach (var leg in parsed.Rporderdetails.Order.Schedulelist.Out.Trainlist.Train) {
|
||||
db.InsertWithInt32Identity(new Leg {
|
||||
lastleg = db.InsertWithInt32Identity(new Leg {
|
||||
TripId = tripId,
|
||||
UserId = int.Parse(HttpContext.Session.GetString("uid")),
|
||||
TrainType = leg.Gattung,
|
||||
|
@ -156,7 +181,7 @@ namespace bahnplan.web.Pages {
|
|||
TicketId = ticketId
|
||||
});
|
||||
|
||||
db.InsertWithInt32Identity(new TicketLeg {
|
||||
lastticketleg = db.InsertWithInt32Identity(new TicketLeg {
|
||||
TicketId = ticketId,
|
||||
TrainType = leg.Gattung,
|
||||
TrainNr = int.Parse(leg.Zugnummer),
|
||||
|
@ -169,7 +194,32 @@ namespace bahnplan.web.Pages {
|
|||
});
|
||||
}
|
||||
|
||||
if (parsed.Rporderdetails.Order.Schedulelist.Ret != null)
|
||||
if (parsed.Rporderdetails.Order.Schedulelist.Ret != null) {
|
||||
db.Insert(new Leg {
|
||||
TripId = tripId,
|
||||
UserId = int.Parse(HttpContext.Session.GetString("uid")),
|
||||
TrainType = "placeholder",
|
||||
TrainNr = lastleg,
|
||||
ArrStation = "_",
|
||||
ArrStationId = 0,
|
||||
ArrTime = "_",
|
||||
DepStation = "_",
|
||||
DepStationId = 0,
|
||||
DepTime = db.Legs.First(p => p.LegId == lastleg).DepTime + "_placeholder"
|
||||
});
|
||||
|
||||
db.Insert(new TicketLeg {
|
||||
TicketId = ticketId2 ?? ticketId,
|
||||
TrainType = "placeholder",
|
||||
TrainNr = lastticketleg,
|
||||
ArrStation = "_",
|
||||
ArrStationId = 0,
|
||||
ArrTime = "_",
|
||||
DepStation = "_",
|
||||
DepStationId = 0,
|
||||
DepTime = db.TicketLegs.First(p => p.TicketLegId == lastticketleg).DepTime + "_placeholder"
|
||||
});
|
||||
|
||||
foreach (var leg in parsed.Rporderdetails.Order.Schedulelist.Ret.Trainlist.Train) {
|
||||
db.InsertWithInt32Identity(new Leg {
|
||||
TripId = tripId,
|
||||
|
@ -197,9 +247,9 @@ namespace bahnplan.web.Pages {
|
|||
DepTime = leg.Dep.Date.Replace("00:00:00", leg.Dep.Time)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
TripId = tripId;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in a new issue