private void addProfileButton_Click(object sender, EventArgs e) { AddProfiles addProfile = new AddProfiles(); // из команд в бд формируем список List <Department> departments = microDb.Departments.ToList(); addProfile.chooseProfileDepartment.DataSource = departments; addProfile.chooseProfileDepartment.ValueMember = "Id"; addProfile.chooseProfileDepartment.DisplayMember = "Title"; DialogResult result = addProfile.ShowDialog(this); if (result == DialogResult.Cancel) { return; } ProfileService profile = new ProfileService(); profile.FirstName = addProfile.addProfileFirstName.Text; profile.LastName = addProfile.addProfileLastName.Text; profile.Department = (Department)addProfile.chooseProfileDepartment.SelectedItem; microDb.ProfileServices.Add(profile); microDb.SaveChanges(); MessageBox.Show("New object was added"); }
// добавление private void addDepartmentButton_Click(object sender, EventArgs e) { AddDepartments addDepartments = new AddDepartments(); DialogResult result = addDepartments.ShowDialog(this); if (result == DialogResult.Cancel) { return; } Department department = new Department(); department.Title = addDepartments.textBox1.Text; microDb.Departments.Add(department); microDb.SaveChanges(); MessageBox.Show("Новый объект добавлен"); }