private void SaveExecute() { try { userData.GivenName = GivenName; userData.Surname = Surname; userData.PersonalNo = PersonalNo; userData.Sex = Sex; userData.PlaceOfResidence = PlaceOfResidence; userData.MaritalStatus = MaritalStatus; userData.Username = Username; userData.Password = SecurePasswordHasher.Hash(Password); //adding new employee to database db.TryAddNewUserData(userData); var userId = db.GetUserDataId(Username); if (userId != 0) { manager.PasswordHint = PasswordHint + "WPF"; manager.OfficeNumber = OfficeNumber; manager.UserDataID = userId; manager.ProjectsCount = ProjectsCount; manager.Email = Email; IsAddedNewManager = db.TryAddNewManager(manager); if (IsAddedNewManager == false) { MessageBox.Show("Something went wrong. New manager is not created."); } else { Logger.Instance.LogCRUD($"[{DateTime.Now.ToString("dd.MM.yyyy hh: mm")}] Created new manager with Personal Number : '{PersonalNo}'"); MessageBox.Show("You have successfully created new manager account."); } var login = new MainWindow(); login.Show(); addNewManagerView.Close(); return; } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private void SaveExecute() { try { userData.GivenName = GivenName; userData.Surname = Surname; userData.PersonalNo = PersonalNo; userData.Sex = Sex; userData.PlaceOfResidence = PlaceOfResidence; userData.MaritalStatus = MaritalStatus; userData.Username = Username; userData.Password = SecurePasswordHasher.Hash(Password); //adding new administrator to database db.TryAddNewUserData(userData); var userId = db.GetUserDataId(Username); if (userId != 0) { administrator.AdministratorTeam = AdministratorTeam; administrator.ExpirationAccountDate = GenerateExpirationAccountDate(); administrator.UserDataID = userId; IsAddedNewAdministrator = db.TryAddNewAdministrator(administrator); if (IsAddedNewAdministrator == false) { MessageBox.Show("Something went wrong. New administrator is not created."); } else { Logger.Instance.LogCRUD($"[{DateTime.Now.ToString("dd.MM.yyyy hh: mm")}] Created new administrator with Personal Number : '{PersonalNo}'"); } addNewAdministratorView.Close(); return; } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private void SaveExecute() { try { var login = new MainWindow(); var managers = db.LoadManagers(); if (managers == null || !managers.Any()) { MessageBox.Show("You can not create the new employee account at the moment."); login.Show(); addNewEmployeeView.Close(); return; } else { userData.GivenName = GivenName; userData.Surname = Surname; userData.PersonalNo = PersonalNo; userData.Sex = Sex; userData.PlaceOfResidence = PlaceOfResidence; userData.MaritalStatus = MaritalStatus; userData.Username = Username; userData.Password = SecurePasswordHasher.Hash(Password); //adding new employee to database db.TryAddNewUserData(userData); var userId = db.GetUserDataId(Username); if (userId != 0) { employee.Position = Position; employee.YearsOfService = yearsOfServiceValue; employee.UserDataID = userId; employee.SectorID = sector.SectorID; employee.ProfessionalQualificationsLevel = ProfessionalQualificationsLevel; if (managers.Any()) { int index = random.Next(0, managers.Count); employee.ManagerID = managers[index].ManagerID; IsAddedNewEmployee = db.TryAddNewEmployee(employee); if (IsAddedNewEmployee == false) { MessageBox.Show("Something went wrong. New employee is not created."); } else { Logger.Instance.LogCRUD($"[{DateTime.Now.ToString("dd.MM.yyyy hh: mm")}] Created new employee with Personal Number : '{PersonalNo}'"); MessageBox.Show("You have successfully created new employee account."); } } login.Show(); addNewEmployeeView.Close(); return; } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
void Submit(object obj) { string password = (obj as PasswordBox).Password; var validate = new DataValidations.DataValidation(); var constants = new Constants(); var validateCompanyData = new CompanyValidations(); if (UserName == Constants.usernamedMaster && SecurePasswordHasher.Verify(password, constants.passwordEmployeeHashed)) { MasterView masterView = new MasterView(); loginView.Close(); masterView.Show(); return; } else if (validateCompanyData.IsCorrectUser(userName, password)) { var db = new CompanyDBRepository(); int userDataId = db.GetUserDataId(userName); if (userDataId != 0) { var typeOfUser = validateCompanyData.GetUserType(userDataId); if (typeOfUser == nameof(tblManager)) { var notImplemented = new NotImplemntedView(); notImplemented.Show(); loginView.Close(); return; } if (typeOfUser == nameof(tblAdministrator)) { var typeOfAdministrator = validateCompanyData.GetAdministratorType(userDataId); if (typeOfAdministrator == "System") { AdministratorView administrator = new AdministratorView(typeOfAdministrator); administrator.Show(); loginView.Close(); return; } else { var notImplemented = new NotImplemntedView(); notImplemented.Show(); loginView.Close(); return; } } if (typeOfUser == nameof(tblEmployee)) { var notImplemented = new NotImplemntedView(); notImplemented.Show(); loginView.Close(); return; } } } else { WarningView warning = new WarningView(loginView); warning.Show("User name or password are not correct!"); return; } }