private void btnSaveCompanyUser_Click(object sender, RoutedEventArgs e) { // Save header for any new change btnSaveHeader_Click(sender, e); #region Validation #endregion if (!IsHeaderCreated) { MainWindow.WarningMessage = ((string)Application.Current.FindResource("Zaglavlje_nije_sačuvano")); return; } var rolesList = RolesFromDB.Where(x => x.IsChecked) .ToList(); UserRolesItemForm.UserRoles = rolesList; UserRolesItemForm.User = CurrentUser; if (UserRolesItemForm.Identifier == Guid.Empty) { UserRolesItemForm.Identifier = Guid.NewGuid(); } var sqLite = new CompanyUserSQLiteRepository(); sqLite.Delete(UserRolesItemForm.Identifier); var response = sqLite.Create(UserRolesItemForm); if (!response.Success) { MainWindow.ErrorMessage = response.Message; } else { Thread td = new Thread(() => DisplayItems()); td.IsBackground = true; td.Start(); UserRolesItemForm = new CompanyUserViewModel(); UserRolesItemForm.Company = CompaniesFromDB.FirstOrDefault(); } }
private void btnEdit_Click(object sender, RoutedEventArgs e) { int compId = SelectedCompanyUserDG?.Company?.Id ?? 0; UserRolesItemForm = SelectedCompanyUserDG; UserRolesItemForm.Company = CompaniesFromDB.FirstOrDefault(x => x.Id == compId); foreach (var item in RolesFromDB) { if (UserRolesItemForm.UserRoles.Any(x => x.Name == item.Name)) { item.IsChecked = true; } else { item.IsChecked = false; } } }
private void btnLogIn_Click(object sender, RoutedEventArgs e) { if (InputIsValid()) { string username = txtUsername.Text; string password = txtPasswordBox.Password; try { //Validate credentials through the authentication service UserSQLiteRepository userSQLiteRepository = new UserSQLiteRepository(); UserViewModel userViewModel = new UserViewModel(); CompanyViewModel company = CompaniesFromDB.Where(x => x.Identifier != Guid.Empty).FirstOrDefault(); CompanyUserViewModel compUser = null; userSQLiteRepository.GetUsers(); UserResponse userResponse = userSQLiteRepository.Authenticate(username, CalculateHash(password, username), company.Id); if (userResponse.Success && userResponse.User != null) { userViewModel = userResponse.User; var companyUser = new CompanyUserSQLiteRepository().GetCompanyUser(company.Id, userViewModel.Identifier); if (companyUser.Success) { compUser = companyUser.CompanyUser; } } else { userResponse = authenticationService.Authenticate(username, CalculateHash(password, username)); if (!userResponse.Success || userResponse.User == null) { throw new UnauthorizedAccessException(); } userViewModel = userResponse.User; var companyUser = new CompanyUserSQLiteRepository().GetCompanyUser(company.Id, userViewModel.Identifier); if (companyUser.Success) { compUser = companyUser.CompanyUser; } } if (compUser == null) { throw new UnauthorizedAccessException(); } //Get the current principal object CustomPrincipal customPrincipal = Thread.CurrentPrincipal as CustomPrincipal; if (customPrincipal == null) { throw new ArgumentException("The application's default thread principal must be set to a CustomPrincipal object on startup."); } //Authenticate the user customPrincipal.Identity = new CustomIdentity( userViewModel.Id, userViewModel.FirstName, userViewModel.LastName, userViewModel.Identifier, userViewModel.Email, company.Id, company.Identifier, company.CompanyName, userViewModel, compUser); if (cbxLanguages.SelectedValue.ToString() == "Serbia") { ResourceDictionary dict = new ResourceDictionary(); dict.Source = new Uri("..\\..\\Resources\\Languages\\StringResources-SRB.xaml", UriKind.Relative); App.Current.Resources.MergedDictionaries.Add(dict); } else if (cbxLanguages.SelectedValue.ToString() == "Germany") { ResourceDictionary dict = new ResourceDictionary(); dict.Source = new Uri("..\\..\\Resources\\Languages\\StringResources-GER.xaml", UriKind.Relative); App.Current.Resources.MergedDictionaries.Add(dict); } else { ResourceDictionary dict = new ResourceDictionary(); dict.Source = new Uri("..\\..\\Resources\\Languages\\StringResources-ENG.xaml", UriKind.Relative); App.Current.Resources.MergedDictionaries.Add(dict); } //Thread td = new Thread(() => { // try // { // AzureNetworkDriveMapper azureNetworkDriveMapper = new AzureNetworkDriveMapper( // DriveLetter: AppConfigurationHelper.Configuration?.AzureNetworkDrive?.DriveLetter, // DriveNetworkPath: AppConfigurationHelper.Configuration?.AzureNetworkDrive?.DriveNetworkPath, // SubDir: AppConfigurationHelper.Configuration?.AzureNetworkDrive?.SubDir, // Username: AppConfigurationHelper.Configuration?.AzureNetworkDrive?.Username, // Password: AppConfigurationHelper.Configuration?.AzureNetworkDrive?.Password, // IsPersistent: AppConfigurationHelper.Configuration?.AzureNetworkDrive?.Persistent ?? true); // if (!String.IsNullOrEmpty(AppConfigurationHelper.Configuration?.AzureNetworkDrive?.DriveNetworkPath)) // { // if (!azureNetworkDriveMapper.IsDriveAndExists()) // azureNetworkDriveMapper.MapDrive(); // } // } catch(Exception ex) // { // MessageBox.Show(ex.Message); // } //}); //td.IsBackground = true; //td.Start(); MainWindow mainWindow = new MainWindow(); mainWindow.Show(); this.Close(); } catch (UnauthorizedAccessException) { notifier.ShowError("Korisničko ime, lozinka ili firma nisu korektni!"); } catch (Exception ex) { notifier?.ShowError("Greška: " + ex?.Message); } } }