コード例 #1
0
        public void DisplayData()
        {
            UserDataLoading = true;

            UserListResponse response = new UserSQLiteRepository()
                                        .GetUsersByPage(MainWindow.CurrentCompanyId, UserSearchObject, currentPage, itemsPerPage);

            if (response.Success)
            {
                UsersFromDB = new ObservableCollection <UserViewModel>(response.Users ?? new List <UserViewModel>());
                totalItems  = response.TotalItems;
            }
            else
            {
                UsersFromDB             = new ObservableCollection <UserViewModel>();
                totalItems              = 0;
                MainWindow.ErrorMessage = response.Message;
            }

            int itemFrom = totalItems != 0 ? (currentPage - 1) * itemsPerPage + 1 : 0;
            int itemTo   = currentPage * itemsPerPage < totalItems ? currentPage * itemsPerPage : totalItems;

            PaginationDisplay = itemFrom + " - " + itemTo + " od " + totalItems;

            UserDataLoading = false;
        }
コード例 #2
0
        private void btnLogIn_Click(object sender, RoutedEventArgs e)
        {
            if (InputIsValid())
            {
                string username = txtUsername.Text;
                string password = txtPasswordBox.Password;
                //CompanyViewModel company = cbxCompanies.SelectedItem as CompanyViewModel;
                try
                {
                    //Validate credentials through the authentication service
                    UserSQLiteRepository userSQLiteRepository = new UserSQLiteRepository();
                    UserViewModel        userViewModel        = new UserViewModel();

                    //userSQLiteRepository.GetUsers();
                    UserResponse userResponse = authenticationService.Authenticate(username, CalculateHash(password, username));
                    if (userResponse.Success && userResponse.User != null)
                    {
                        userResponse = authenticationService.Authenticate(username, CalculateHash(password, username));
                        if (!userResponse.Success || userResponse.User == null)
                        {
                            throw new UnauthorizedAccessException();
                        }

                        userViewModel = userResponse.User;
                    }


                    //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,
                        userViewModel.Roles);

                    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);
                }
            }
        }
コード例 #3
0
        private void btnSaveHeader_Click(object sender, RoutedEventArgs e)
        {
            IsHeaderCreated = false;

            if (CurrentUser.Identifier == Guid.Empty)
            {
                CurrentUser.Identifier = Guid.NewGuid();
            }

            #region Validation
            if (String.IsNullOrEmpty(CurrentUser.Username))
            {
                if (CurrentUser.Id < 1 && String.IsNullOrEmpty(txtPassword.Password))
                {
                    MainWindow.ErrorMessage = ((string)Application.Current.FindResource("Morate_uneti_korisničko_imeUzvičnik"));
                    return;
                }
            }

            if (!String.IsNullOrEmpty(txtPassword.Password))
            {
                if (txtPassword.Password != txtPasswordRepeat.Password)
                {
                    MainWindow.ErrorMessage = ((string)Application.Current.FindResource("Unete_lozinke_se_moraju_poklapatiUzvičnik"));
                    return;
                }
                else
                {
                    CurrentUser.Password = CalculateHash(txtPassword.Password, CurrentUser.Username);
                }
            }
            #endregion

            CurrentUser.IsSynced  = false;
            CurrentUser.UpdatedAt = DateTime.Now;
            var sqLite = new UserSQLiteRepository();
            sqLite.Delete(CurrentUser.Identifier);
            var response = sqLite.Create(CurrentUser);
            if (response.Success)
            {
                IsHeaderCreated = true;
            }
            else
            {
                MainWindow.ErrorMessage = response.Message;
            }
        }
コード例 #4
0
        private void PopulateFromDb(string filterString = "")
        {
            Application.Current.Dispatcher.BeginInvoke(
                System.Windows.Threading.DispatcherPriority.Normal,
                new Action(() =>
            {
                new UserSQLiteRepository().Sync(UserService);

                UserListResponse regionResp = new UserSQLiteRepository().GetUsersForPopup(MainWindow.CurrentCompanyId, filterString);
                if (regionResp.Success)
                {
                    UsersFromDB = new ObservableCollection <UserViewModel>(regionResp.Users ?? new List <UserViewModel>());
                }
                else
                {
                    UsersFromDB = new ObservableCollection <UserViewModel>();
                }
            })
                );
        }
コード例 #5
0
        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);
                }
            }
        }