private void SetRole() { if (SelectedRole != null && SelectedEmployee != null) { SelectedEmployee.Role = DBContext.Instance.Roles.Single(e => e.Id == SelectedRole.Id); SelectedEmployee.Update(); RaisePropertyChanged("SelectedEmployee"); } }
private void DeleteSelectedEmployee() { var confirmResult = MessageBox.Show("Bent u zeker dat u " + SelectedEmployee.Name.ToString() + " wenst te verwijderen?", "Medewerker verwijder waarchuwing", MessageBoxButton.YesNo); if (confirmResult == MessageBoxResult.Yes) { SelectedEmployee.IsArchived = true; RaisePropertyChanged("SelectedEmployee"); SelectedEmployee.Update(); SelectedEmployee = null; RefreshView(); } }
private void SaveEmployee() { if (String.IsNullOrEmpty(SelectedEmployee.FirstName)) { MessageBox.Show("Please Enter First Name", "First Name Required", MessageBoxButton.OK, MessageBoxImage.Error); return; } if (String.IsNullOrEmpty(SelectedEmployee.LastName) ) { MessageBox.Show("Please Enter Last Name", "Last Name Required", MessageBoxButton.OK, MessageBoxImage.Error); return; } if (String.IsNullOrEmpty(SelectedEmployee.MobileNumber)) { MessageBox.Show("Please Enter Mobile Number", "Mobile Number Required", MessageBoxButton.OK, MessageBoxImage.Error); return; } if (String.IsNullOrEmpty(SelectedEmployee.State)) { MessageBox.Show("Please Enter State", "State Required", MessageBoxButton.OK, MessageBoxImage.Error); return; } if (String.IsNullOrEmpty(SelectedEmployee.Suburb)) { MessageBox.Show("Please Enter Suburb", "Suburb Required", MessageBoxButton.OK, MessageBoxImage.Error); return; } if (String.IsNullOrEmpty(SelectedEmployee.PostCode)) { MessageBox.Show("Please Enter Postcode", "Postcode Required", MessageBoxButton.OK, MessageBoxImage.Error); return; } if (String.IsNullOrEmpty(SelectedEmployee.Gender)) { MessageBox.Show("Please Enter Gender", "Gender Required", MessageBoxButton.OK, MessageBoxImage.Error); return; } if (String.IsNullOrEmpty(SelectedEmployee.EmployeeType)) { MessageBox.Show("Please Enter Employee Type", "Employee Type Required", MessageBoxButton.OK, MessageBoxImage.Error); return; } if (String.IsNullOrEmpty(SelectedEmployee.Street)) { MessageBox.Show("Please Enter Street", "Street Required", MessageBoxButton.OK, MessageBoxImage.Error); return; } if (String.IsNullOrEmpty(SelectedEmployee.Email)) { MessageBox.Show("Please Enter Email", "Email Required", MessageBoxButton.OK, MessageBoxImage.Error); return; } if (!Regex.Match(SelectedEmployee.LastName, "^[a-zA-Z\\s\\,]*$").Success || String.IsNullOrEmpty(SelectedEmployee.LastName)) { MessageBox.Show("Not a valid Last Name"); return; } if (!Regex.Match(SelectedEmployee.FirstName, "^[a-zA-Z\\s\\,]*$").Success || String.IsNullOrEmpty(SelectedEmployee.LastName)) { MessageBox.Show("Not a valid First Name"); return; } if (!Regex.Match(SelectedEmployee.MobileNumber, "^0[0-9]{9}$").Success) { MessageBox.Show("Enter valid phone number.", "Phone Number", MessageBoxButton.OK, MessageBoxImage.Error); return; } SelectedEmployee.UserID = Convert.ToInt32(SelectedEmployeeUserId); if (SelectedEmployee.EmployeeID == 0) { try { SelectedEmployee.Insert(); MessageBox.Show("Thank you! The new Employee's details have been added to the Database.", "Add Employee", MessageBoxButton.OK, MessageBoxImage.Information); } catch (Exception) { MessageBox.Show("Something Went Wrong, But we Dont know what! Employee details was not added to the database"); } } else { try { SelectedEmployee.Update(); MessageBox.Show("The employee's details have been updated in the Database.", "Update Employee?", MessageBoxButton.OK, MessageBoxImage.Information); } catch (Exception ex) { MessageBox.Show("An Error Occured, The Employee Details were not updated. Please Contact your System Administrator.", "Update Employee?" + ex.Message); } } IsEnabledSave = true; IsEnabledAdd = true; IsEnabledDelete = true; }
private void UpdateSelectedEmployee() { SelectedEmployee.Update(); }