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 buttonAddWorker_Click(object sender, EventArgs e) { var lastName = textBoxLastName.Text; var firstName = textBoxFirstName.Text; var middleName = textBoxMiddleName.Text; if (String.IsNullOrWhiteSpace(lastName) || String.IsNullOrWhiteSpace(middleName) || String.IsNullOrWhiteSpace(firstName)) { MessageBox.Show("Введите ФИО"); return; } decimal salary; int los; try { salary = Decimal.Parse(textBoxSalary.Text); los = Int32.Parse(textBoxLoS.Text); } catch (Exception) { MessageBox.Show("Неверные данные"); return; } var worker = new Worker { FirstName = firstName, MiddleName = middleName, LastName = lastName, Salary = salary, LengthOfService = los }; Server.Context.Workers.Add(worker); Server.Context.SaveChanges(); }