private async void btnSave_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                // Encrypts the user password
                NewDesktopUser.EncryptedPassword = Encryption.EncryptPassword(NewDesktopUser.Salt, pwdPassword.Password);

                try
                {
                    // Create new user
                    NewDesktopUser = _userRepo.Add(NewDesktopUser);
                    await _userRepo.SaveChangesAsync();
                }
                catch (Exception)
                {
                    MessageBox.Show(LangResource.ErrSaveFailedContent, LangResource.ErrSaveFailedTitle);
                    NewDesktopUser.EncryptedPassword = null;
                    pwdPassword.Password             = null;
                }

                // Opens up the mainwindow
                NavigationWindow naviWindow = new NavigationWindow(NewDesktopUser.ID);
                naviWindow.Show();

                this.Close();
            }
            catch (Exception)
            {
                // TODO ERROR MESSAGE

                pwdPassword.Password = null;
                throw;
            }
        }
        private async void btnSave_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                // Encrypts the user password
                NewDesktopUser.EncryptedPassword = Encryption.EncryptPassword(NewDesktopUser.Salt, pwdPassword.Password);

                // Create the new user
                NewDesktopUser = _userRepo.Add(NewDesktopUser);
                await _userRepo.SaveChangesAsync();

                SendMailToAdmin();
                SendMailToNewUser();

                LoginWindow login = new LoginWindow();
                login.Show();

                MessageBox.Show(LangResource.NewAccountMadeInfo);

                this.Close();
            }
            catch (UsernameTaken)
            {
                MessageBox.Show(LangResource.UsernameIsTaken);
                pwdPassword.Password = null;
            }
            catch (Exception)
            {
                pwdPassword.Password = null;
                MessageBox.Show(LangResource.ErrSaveFailedContent, LangResource.ErrSaveFailedTitle);
            }
        }
        private void MakeAdmin(object sender, RoutedEventArgs e)
        {
            try
            {
                SetLanguageDictionary();

                DesktopUser newAdmin = ((FrameworkElement)sender).DataContext as DesktopUser;

                string messageboxContent = String.Format(LangResource.MBContentMakeUserAdmin, newAdmin.FullName);
                string messageboxTitle   = String.Format(LangResource.MBTitleMakeUserAdmin, newAdmin.FullName);

                MessageBoxManager.Yes = LangResource.Yes;
                MessageBoxManager.No  = LangResource.No;
                MessageBoxManager.Register();

                if (MessageBox.Show(messageboxContent,
                                    messageboxTitle,
                                    MessageBoxButton.YesNo,
                                    MessageBoxImage.Warning)
                    == MessageBoxResult.Yes)
                {
                    _userRepo.AssignNewAdmin(newAdmin);
                    _userRepo.SaveChangesAsync();

                    LoginWindow login = new LoginWindow();
                    login.Show();

                    NavigationWindow win = (NavigationWindow)Window.GetWindow(this);

                    win.Close();

                    MessageBoxManager.Unregister();
                }
                else
                {
                    MessageBoxManager.Unregister();
                }
            }
            catch (Exception)
            {
                MessageBox.Show(LangResource.ErrUpdateOverviewFailed);
                MessageBoxManager.Unregister();
            }
        }
Exemple #4
0
        private async void btnSave_Click(object sender, RoutedEventArgs e)
        {
            // If somehow no language was selected, choose dutch
            if (_preferredLanguage == null && listContainsDesktopLanguages)
            {
                rbPreferNL.IsChecked = true;
            }

            // Sets the preferred language for the user
            _currentUser.PreferredLanguageID = _preferredLanguage.ID;

            // Update the user and save
            await _userRepo.UpdateAsync(_currentUser);

            await _userRepo.SaveChangesAsync();

            OnAccountSave(_currentUser);
        }