private Train CreateTrain(Station startStation) { var driver = new Worker { FirstName = "Андрей", MiddleName = "Андрей", LastName = "Андрей", Salary = 400m, LengthOfService = 1 }; var cond1 = new Worker { FirstName = "cond1", MiddleName = "cond1", LastName = "cond1", Salary = 200, LengthOfService = 1 }; var cond2 = new Worker { FirstName = "cond2", MiddleName = "cond2", LastName = "cond2", Salary = 200, LengthOfService = 1 }; var cond3 = new Worker { FirstName = "cond3", MiddleName = "cond3", LastName = "cond3", Salary = 200, LengthOfService = 1 }; var train = new Train { Name = "First Train", CurrentStation = startStation, Driver = driver, Velocity = 60 }; var wagon1 = new Wagon {MaxPassengerCount = 3, Conductor = cond1}; var wagon2 = new Wagon { MaxPassengerCount = 3, Conductor = cond2 }; var wagon3 = new Wagon { MaxPassengerCount = 3, Conductor = cond3 }; train.Wagons.Add(wagon1); train.Wagons.Add(wagon2); train.Wagons.Add(wagon3); return train; }
private void buttonAddWagon_Click(object sender, EventArgs e) { int maxPassengerCount; try { maxPassengerCount = Int32.Parse(textBoxMaxPassengersCount.Text); } catch (Exception) { MessageBox.Show("Неверные данные"); return; } var conductor = comboBoxFreeConductors.SelectedItem as Worker; if (conductor == null) return; var wagon = new Wagon { MaxPassengerCount = maxPassengerCount, Conductor = conductor }; Server.Context.Wagons.Add(wagon); Server.Context.SaveChanges(); }