コード例 #1
0
        } // функция регистрации

        private async void CreateAccount(object sender, RoutedEventArgs e)
        {
            string name  = Name.Text != "" ? Name.Text : "New user";
            string email = Email.Text;

            string badgeError = (string)Application.Current.Resources["NotifyErrorBadgeEN"];
            string messageUE  = (string)Application.Current.Resources["NotifyUncorrectEmailEN"];
            string messageSE  = (string)Application.Current.Resources["NotifyServerErrorEN"];

            if (Properties.Settings.Default.DefaultLanguage.Equals(new CultureInfo("ru-RU")))
            {
                badgeError = (string)Application.Current.Resources["NotifyErrorBadgeRU"];
                messageUE  = (string)Application.Current.Resources["NotifyUncorrectEmailRU"];
                messageSE  = (string)Application.Current.Resources["NotifyServerErrorRU"];
            }

            if (!ValidateEmail(email))
            {
                Manager.CreateMessage()
                .Accent("#8b0000")
                .Animates(true)
                .AnimationInDuration(0.55)
                .AnimationOutDuration(0.55)
                .Background("#333")
                .HasBadge(badgeError)
                .HasMessage(messageUE)
                .Dismiss().WithDelay(2500)
                .Queue();
                Email.Text = "";
                Email.Focus();
                return;
            }
            Loading(true);
            Account _account = await AccountOperations.GetAccountById(_userid);

            _account.Name  = name;
            _account.Email = email;
            OperationsResponse response = await AccountOperations.Update(_account);

            switch (response)
            {
            case OperationsResponse.Ok:

                MainWindow mainWindow = new MainWindow();     // creating MainWindow

                // creating ViewModel for MainWindow
                MainWindowViewModel vm = new MainWindowViewModel(_login);

                mainWindow.DataContext           = vm;
                mainWindow.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                mainWindow.Show();

                Window.GetWindow(this)?.Close();     // close auth modal window
                break;

            case OperationsResponse.ServerError:
                Manager.CreateMessage()
                .Accent("#8b0000")
                .Animates(true)
                .AnimationInDuration(0.55)
                .AnimationOutDuration(0.55)
                .Background("#333")
                .HasBadge(badgeError)
                .HasMessage(messageSE)
                .Dismiss().WithDelay(2500)
                .Queue();
                break;
            }
            Loading(false);
        } // функция создания аккаунта