public static void FillTicket(Ticket ticket) { var route = ticket.Route; var inTime = GetTimeTillStationOnRoute(route.Id, ticket.InStationId); var outTime = GetTimeTillStationOnRoute(route.Id, ticket.OutStationId); ticket.Length = GetLengthsBetweenStations(ticket.InStationId, ticket.OutStationId); ticket.Price = CalcCost(ticket.InStationId, ticket.OutStationId); ticket.InTime = inTime; ticket.OutTime = outTime; }
public void Foo() { var temp = ""; var stations = Context.Stations.ToList(); foreach (var station in stations) { temp += station.Name + Environment.NewLine; } var minskP = stations.First(s => s.Name == "Минск-Пассажирский"); var orshaZ = stations.First(s => s.Name == "Орша-Западная"); var step = stations.First(s => s.Name == "Степянка"); var jod = stations.First(s => s.Name == "Жодино"); //var route = new Route(); //route.StartStation = minskP; //route.EndStation = orshaZ; //route.StartTime = CreateTrainTime(12, 00); //route.EndTime = route.StartTime; //route.Train = CreateTrain(minskP); //Context.Routes.Add(route); //Context.SaveChanges(); //FillRoute(route); //Context.SaveChanges(); var route = Context.Routes.First(); var passenger = new Passenger { FirstName = "Pass1", MiddleName = "Pass1", LastName = "Pass1", IdentityNumber = "12345" }; var ticket = new Ticket(); ticket.Route = route; ticket.Passenger = passenger; ticket.Price = 123; ticket.InStation = step; ticket.OutStation = jod; ticket.BuyDate = DateTime.Now; ticket.Wagon = route.Train.Wagons.First(); Context.Tickets.Add(ticket); Context.SaveChanges(); FillTicket(ticket); GetNetSegmentsByStationId(1); GetStationsOnSegmentsByStationId(1); GetLengthsBetweenStations(3, 3); }
private void buttonGetTicket_Click(object sender, EventArgs e) { var route = comboBox1.SelectedItem as Route; if (route == null) return; var inStation = comboBoxInTicketStations.SelectedItem as Station; if (inStation == null) return; var outStation = comboBoxOutTicketStations.SelectedItem as Station; if (outStation == null) return; var wagon = comboBoxTicketWagons.SelectedItem as Wagon; if (wagon == null) return; if (wagon.PassengerCount >= wagon.MaxPassengerCount) { MessageBox.Show("В вагоне больше нет места"); } var pass = comboBoxTicketPassenger.SelectedItem as Passenger; if (pass == null) return; var ticket = new Ticket { Route = route, Passenger = pass, Price = Server.CalcCost(inStation.Id, outStation.Id), Length = Server.GetLengthsBetweenStations(inStation.Id, outStation.Id), InStation = inStation, OutStation = outStation, Wagon = wagon, BuyDate = DateTime.Now }; Server.Context.Tickets.Add(ticket); Server.Context.SaveChanges(); Server.FillTicket(ticket); wagon.PassengerCount++; Server.Context.SaveChanges(); textBoxTicket.Text = ticket.ToLongString(); }