private void CRUDItemEmployee(object sender, RoutedEventArgs e) { PasswordEncode passwordEncode = new PasswordEncode(); var action = (e.Source as Button).Content.ToString(); Console.WriteLine("=================>>>>>>>>>>>>CRUD Click: " + $"{action}"); /*MessageBox.Show(keyword);*/ string _nameEmp = FullnameEmployeeCRUD.Text; string _emailEmp = EmailEmployeeCRUD.Text; /*float _pRoom = float.Parse(PriceRoomCRUD.Text);*/ string _passwordEmp = PasswordEmployeeCRUD.Text; string hashed = passwordEncode.EncodePasswordToBase64(_passwordEmp); /*TypeRoom _typeRoomId = (TypeRoom)RoomTypeCb.SelectedItem;*/ // gives you the required string var _typeRoleId = roleViewModel.FindRoleIdByName("ROLE_EMPLOYEE").Id; if (RoleTypeCb.SelectedItem != null) { _typeRoleId = (RoleTypeCb.SelectedItem as Role).Id; } else { _typeRoleId = roleViewModel.FindRoleIdByName("ROLE_EMPLOYEE").Id; } switch (action) { case "Add": /* _nameRoom = NameRoomCRUD.Text; * _noteRoom = NoteRoomCRUD.Text; * _priceRoom = float.Parse(PriceRoomCRUD.Text); * * *//*TypeRoom _typeRoomId = (TypeRoom)RoomTypeCb.SelectedItem;*//* // gives you the required string * _typeRoomId = (RoomTypeCb.SelectedItem as TypeRoom).Id;*/ messageError = "Information Add Employee not blank"; captionError = "Confirmation"; MessageBoxButton buttonAddEmp = MessageBoxButton.YesNo; MessageBoxImage iconAddEmp = MessageBoxImage.Question; if (_nameEmp.Length == 0 || _emailEmp.Length == 0 || _passwordEmp.Length == 0) { MessageBox.Show(messageError, captionError, buttonAddEmp, iconAddEmp); } else { int _idAdd = 0; Console.WriteLine("=================>>>>>>>>>>>>Name Employee add: " + $"{_nameEmp}"); Console.WriteLine("=================>>>>>>>>>>>>Email add: " + $"{_emailEmp}"); Console.WriteLine("=================>>>>>>>>>>>>password add: " + $"{_passwordEmp}"); Console.WriteLine("=================>>>>>>>>>>>>TypeRoleId Room add: " + $"{_typeRoleId}"); Employee employee = new Employee() { Id = _idAdd, Fullname = _nameEmp, Email = _emailEmp, RoleId = _typeRoleId, Password = hashed }; employeeViewModel.Add(employee); } break; case "Update": messageError = "Information Update Employee not blank"; captionError = "Confirmation"; MessageBoxButton buttonUpdateEmp = MessageBoxButton.YesNo; MessageBoxImage iconUpdateEmp = MessageBoxImage.Question; if (IdEmployeeCRUD.Text.Length == 0) { messageError = "Employee not exist"; MessageBox.Show(messageError, captionError, buttonUpdateEmp, iconUpdateEmp); return; } if (_nameEmp.Length == 0 || _emailEmp.Length == 0) { MessageBox.Show(messageError, captionError, buttonUpdateEmp, iconUpdateEmp); } else { int _idUpdate = int.Parse(IdEmployeeCRUD.Text); Console.WriteLine("==============>>>>>>>>>>>>> ID UPDATE ROOM: " + $"{_idUpdate}"); Console.WriteLine("=================>>>>>>>>>>>>Name Employee update: " + $"{_nameEmp}"); Console.WriteLine("=================>>>>>>>>>>>>Email update: " + $"{_emailEmp}"); Console.WriteLine("=================>>>>>>>>>>>>password update: " + $"{_passwordEmp}"); Console.WriteLine("=================>>>>>>>>>>>>TypeRoleId Room update: " + $"{_typeRoleId}"); if (_passwordEmp.Trim().Length == 0) { Console.WriteLine("password is blank"); Employee employeeUpdate = new Employee() { Id = _idUpdate, Fullname = _nameEmp, Email = _emailEmp, RoleId = _typeRoleId, }; employeeViewModel.UpdateNotPass(employeeUpdate); } else { Employee employeeUpdate = new Employee() { Id = _idUpdate, Fullname = _nameEmp, Email = _emailEmp, RoleId = _typeRoleId, Password = hashed }; employeeViewModel.Update(employeeUpdate); } } break; case "Delete": messageError = "Information Update Employee not blank"; captionError = "Confirmation"; MessageBoxButton buttonDeleteEmp = MessageBoxButton.YesNo; MessageBoxImage iconDeleteEmp = MessageBoxImage.Question; if (IdEmployeeCRUD.Text.Length == 0) { messageError = "Employee not exist delete"; MessageBox.Show(messageError, captionError, buttonDeleteEmp, iconDeleteEmp); return; } else { int _idDelete = (EmployeesGrid.SelectedItem as Employee).Id; Console.WriteLine("=================>>>>>>>>>>>>> id delete: " + $"{_idDelete}"); string message = "Are you sure?"; string caption = "Confirmation"; MessageBoxButton buttons = MessageBoxButton.YesNo; MessageBoxImage icon = MessageBoxImage.Question; if (MessageBox.Show(message, caption, buttons, icon) == MessageBoxResult.Yes) { employeeViewModel.UpdateIsDeleted(_idDelete); LoadContent(); } else { // Cancel code here } } break; } }