Ejemplo n.º 1
0
 private void OnEditEmployee(object sender, EventArgs e)
 {
     using (var editEmployeeDialog = new EmployeeForm(Departments, selectedEmployee))
     {
         if (editEmployeeDialog.ShowDialog() == DialogResult.OK)
         {
             var  editedEmployee = editEmployeeDialog.Employee;
             bool success        = false;
             using (CompanyContext db = new CompanyContext())
             {
                 try
                 {
                     // Изменяем выбранного сотрудника
                     db.Entry(editedEmployee).State = EntityState.Modified;
                     db.SaveChanges();
                     success = true;
                 }
                 catch (Exception)
                 {
                     ShowErrorDialog("Ошибка сохранения пользователя в базе данных.");
                 }
                 if (success)
                 {
                     dataGridView.DataSource = null;
                     dataGridView.DataSource = bindEmployees;
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
 private void OnCreateEmployee(object sender, EventArgs e)
 {
     using (var newEmployeeDialog = new EmployeeForm(Departments))
     {
         if (newEmployeeDialog.ShowDialog() == DialogResult.OK)
         {
             var newEmployee = newEmployeeDialog.Employee;
             using (CompanyContext db = new CompanyContext())
             {
                 try
                 {
                     db.Empoyees.Add(newEmployee);
                     db.SaveChanges();
                     Employees.Add(newEmployee);
                 }
                 catch (Exception)
                 {
                     ShowErrorDialog("Ошибка сохранения пользователя в базе данных.");
                 }
             }
         }
     }
 }