public void SaveExecute(object parametar) { try { if (User.UserId == 0) { var passwordBox = parametar as PasswordBox; var password = passwordBox.Password; User.Password = password; User.GenderId = selectedGender.GenderId; User.MaritalStatusId = selectedMaritalStatus.MaritalStatusId; User.RoleId = 2; MessageBoxResult result = MessageBox.Show("Are you sure you want to save the new Administrator", "Add New Admin", MessageBoxButton.YesNo); if (result == MessageBoxResult.Yes) { bool uniqueUser = service.CheckUsernameUser(User.Username); bool uniqueUserMaster = service.CheckUsernameMasterUser(User.Username); if (!uniqueUser && !uniqueUserMaster) { int userId = service.AddCompanyUser(User); if (userId != 0) { Admin.CompanyUserId = userId; Admin.AdministratorTypeId = selectedType.AdministratorTypeId; Admin.ExpirationDate = DateTime.Now.AddDays(7); if (service.AddAdminUser(Admin) != 0) { MessageBox.Show("You have successfully added new administrator"); Logging.LoggAction("AddNewAdmnViewModel", "Info", "Succesfull add new Admin"); MasterAdminView masterView = new MasterAdminView(); masterView.Show(); addNewAdminView.Close(); } } } else { MessageBox.Show("User name is not unique!"); } } else { MasterAdminView masterView = new MasterAdminView(); masterView.Show(); addNewAdminView.Close(); } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
public void SaveUserExecute(string parametar1, string parametar2) { MessageBoxResult result = MessageBox.Show("Are you sure you want to registrate?", "Registration", MessageBoxButton.YesNo); if (result == MessageBoxResult.Yes) { User.Password = parametar1; User.GenderId = selectedGender.GenderId; User.MaritalStatusId = selectedMaritalStatus.MaritalStatusId; try { if (User.UserId == 0) { bool uniqueUserName = service.CheckUsernameUser(User.Username); bool uniqueJMBG = service.CheckJmbg(User.Jmbg); bool uniqueEmail = service.CheckUniqueEmail(Menager.Email); if (!uniqueUserName && !uniqueEmail && !uniqueJMBG) { int userId = service.AddCompanyUser(User); if (userId != 0) { if (User.RoleId == 1) { Menager.UserId = userId; Menager.NumOfSuccessfulProjects = 0; Menager.BackupPassword = parametar2 + "WPF"; if (service.AddMenagerUser(Menager) != 0) { MessageBox.Show("You have successfully registrate!"); Logging.LoggAction("RegistrationMenager", "Info", "Succesfull registrate new menager"); MainWindow mainView = new MainWindow(); mainView.Show(); registrationView.Close(); } } else if (User.RoleId == 3) { Random random = new Random(); menager = ManagerList[random.Next(0, ManagerList.Count)]; Worker.UserId = userId; Worker.SectorId = selectedSector.SectorId; Worker.PositionId = selectedPosition.PositionId; Worker.QualificationsId = selectedQualification.QualificationsId; Worker.ManagerId = menager.ManagerId; if (service.AddWorkerUser(Worker) != 0) { MessageBox.Show("You have successfully registrate!"); Logging.LoggAction("RegistrationWorker", "Info", "Succesfull registrate new worker"); MainWindow mainView = new MainWindow(); mainView.Show(); registrationView.Close(); } } } } else if (uniqueUserName) { MessageBox.Show("Username is not unique!"); } else if (uniqueJMBG) { MessageBox.Show("JMBG is not unique!"); } else if (uniqueEmail) { MessageBox.Show("Email is not unique!"); } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); Logging.LoggAction("RegistrationMenager", "Error", ex.ToString()); } } }