Пример #1
0
        private async void CreateAccount()
        {
            IServerChanger window = (IServerChanger)Window.GetWindow(View);

            if (Username == null || Username.Length == 0)
            {
                MessageBox.Show("Username is empty!", "Hanksite", MessageBoxButton.OK);
                return;
            }

            IConfirmedPasswordProvider passwordProvider = (IConfirmedPasswordProvider)View;
            string password          = passwordProvider.GetPassword();
            string confirmedPassword = passwordProvider.GetConfirmedPassword();

            if (password == null || password.Length == 0)
            {
                MessageBox.Show("Password is empty!", "Hanksite", MessageBoxButton.OK);
                return;
            }

            if (password != confirmedPassword)
            {
                MessageBox.Show("Password differs from confirmed password!", "Hanksite", MessageBoxButton.OK);
                return;
            }

            IsPageEnabled = false;
            window.Disable();

            bool success;

            try
            {
                success = await accounts.CreateAccount(window.GetServer(), Username, password);
            }
            catch (System.Exception e)
            {
                MessageBox.Show("An error has occured while connecting to the server.\n" + e.Message, "Hanksite", MessageBoxButton.OK);
                IsPageEnabled = true;
                window.Enable();
                return;
            }

            if (!success)
            {
                IsPageEnabled = true;
                window.Enable();
                MessageBox.Show("The given username already exists!", "Hanksite", MessageBoxButton.OK);
                return;
            }

            window.Enable();
            NavigationService.GetNavigationService(View).Navigate(new MainMenu());
            window.HideChangeServerButton();
        }