public void RegisterUserForAuthentication(string username, SecureString password)
        {
            UserManager userManager = new UserManager();
            var currentApplicationUser = userManager.GetUser(username, password);

            AuthenticationManager.IsAnAdmin = currentApplicationUser.IsAdmin;
            AuthenticationManager.IsReadOnly = currentApplicationUser.IsReadOnly;
            AuthenticationManager.CurrentUser = currentApplicationUser.Username;

            if (this.ValidAuthenticationEvent != null)
                this.ValidAuthenticationEvent(this, EventArgs.Empty);
        }
        private void DeleteUser_Click(object sender, RoutedEventArgs e)
        {
            if(this.selectedUser != null)
            {
                UserManager manager = new UserManager();
                manager.DeleteUser(this.selectedUser.UserId);

                this.users.Remove(selectedUser);
                this.AutoCompleteBox.RemoveItem(this.selectedUser.Username);
                this.selectedUser = null;

                this.ClearFields();
            }
        }
        private void EditUser_Click(object sender, RoutedEventArgs e)
        {
            string username = this.Username.Text;
            if(string.IsNullOrWhiteSpace(username) == false && this.selectedUser != null)
            {
                UserManager manager = new UserManager();
                var updatedUser = manager.UpdateUser(this.selectedUser.UserId, username, this.Password.SecurePassword, this.IsAdminCheckBox.IsChecked.Value);

                this.users.Remove(selectedUser);
                this.users.Add(updatedUser);
                this.selectedUser = updatedUser;

                this.MessageLabel.Content = "User is successfuly updated.";
                this.MessageLabel.Foreground = new SolidColorBrush(Color.FromRgb(0, 204, 0));

                this.ClearFields();
            }
        }
        private bool IsUserCredentialsCorrect(string username, SecureString password)
        {
            UserManager userManager = new UserManager();
            bool isUserCredentialsCorrect = true;
            try
            {
                userManager.GetUser(username, password);
            }
            catch (ArgumentNullException)
            {
                isUserCredentialsCorrect = false;
            }
            catch (ArgumentException)
            {
                isUserCredentialsCorrect = false;
            }

            return isUserCredentialsCorrect;
        }
        private void CreateUser_Click(object sender, RoutedEventArgs e)
        {
            UserManager manager = new UserManager();
            bool userExists = manager.CheckUsernameExists(this.Username.Text);
            if (string.IsNullOrWhiteSpace(this.Username.Text) == false &&
                userExists == false &&
                string.IsNullOrWhiteSpace(this.Password.SecurePassword.ConvertToUnsecureString()) == false)
            {
                manager.CreateUser(this.Username.Text, this.Password.SecurePassword, this.IsAdminCheckBox.IsChecked.Value);
                this.MessageLabel.Content = "Successfuly created the application user.";
                this.MessageLabel.Foreground = new SolidColorBrush(Color.FromRgb(0, 204, 0));

                this.ClearFields();
            }
            else if (userExists)
            {
                this.MessageLabel.Content = "The application user already exists.";
                this.MessageLabel.Foreground = new SolidColorBrush(Color.FromRgb(255, 0, 0));

                this.ClearFields();
            }
        }
 private void UserControl_Loaded(object sender, RoutedEventArgs e)
 {
     Task task = Task.Factory.StartNew(() =>
     {
         UserManager manager = new UserManager();
         users = manager.GetAll();
     });
     task.ContinueWith(next =>
     {
         // Update the main Thread as it is the owner of the UI elements
         this.Dispatcher.Invoke((Action)(() =>
         {
             foreach (var user in users)
             {
                 this.AutoCompleteBox.AddItem(new AutoCompleteModel(user.Username, user.Username));
             }
         }));
     });
 }