Example #1
0
 private bool DeleteById(int employeeId)
 {
     using (ERPEF entity = new ERPEF())
     {
         Employee employee = entity.Employees.SingleOrDefault(
             n => n.EmployeeId == employeeId
             );
         entity.Employees.Remove(employee);
         return(entity.SaveChanges() > 0);
     }
 }
Example #2
0
 public void ExecuteSave(object sender, RoutedEventArgs e)
 {
     try
     {
         using (ERPEF entity = new ERPEF())
         {
             if (labelId.Content != null && labelId.Content.ToString() != "")
             {
                 int employeeId = Convert.ToInt32(labelId.Content);
                 var employee   =
                     entity.Employees.SingleOrDefault(
                         n => n.EmployeeId == employeeId
                         );
                 employee.FirstName   = textBoxFirstName.Text;
                 employee.LastName    = textBoxLastName.Text;
                 employee.Address     = textBoxAddress.Text;
                 employee.DateOfBirth = DateOfBirth.SelectedDate;
                 employee.Telephone   = textBoxTelephone.Text;
                 employee.Cellphone   = textBoxCellphone.Text;
                 employee.Email       = textBoxEmail.Text;
                 employee.StateCode   = Convert.ToString(comboBoxStates.SelectedValue);
                 if (entity.SaveChanges() > 0)
                 {
                     MessageBox.Show("Success to update employee!");
                 }
                 else
                 {
                     MessageBox.Show("Failed to update employee or nothing changes!");
                 }
             }
             else
             {
                 var employee = new Employee()
                 {
                     FirstName   = textBoxFirstName.Text,
                     LastName    = textBoxLastName.Text,
                     Address     = textBoxAddress.Text,
                     DateOfBirth = DateOfBirth.SelectedDate,
                     Telephone   = textBoxTelephone.Text,
                     Cellphone   = textBoxCellphone.Text,
                     Email       = textBoxEmail.Text,
                     StateCode   = Convert.ToString(comboBoxStates.SelectedValue),
                     IsActivated = true
                 };
                 entity.Employees.Add(employee);
                 if (entity.SaveChanges() > 0)
                 {
                     MessageBox.Show("Success to add new employee!");
                 }
                 else
                 {
                     MessageBox.Show("Failed to add new employee or duplicate data!");
                 }
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }