예제 #1
0
        private async void SelectImageButton_Click(object sender,
                                                   RoutedEventArgs e)
        {
            if (LoadImageFromUrlRadioButton.IsChecked == true)
            {
                var title = LocalizationUtils
                            .GetLocalized("InsertingImageTitle");
                var message = LocalizationUtils
                              .GetLocalized("EnterUrl");

                var url = await DialogManager.ShowSinglelineTextDialog(
                    title, message)
                          .ConfigureAwait(true);

                await SelectImage(url)
                .ConfigureAwait(true);
            }
            else if (LoadImageFromGalleryRadioButton.IsChecked == true)
            {
                NavigationController.Instance.RequestPage <AnonymGallerySearchPage>(new AnonymGallerySearchViewModel
                {
                    ImageSelectionDelegate = SelectImage
                });
            }
            else if (LoadImageFromTenorRadioButton.IsChecked == true)
            {
                NavigationController.Instance.RequestPage <TenorSearchPage>(new TenorSearchViewModel
                {
                    ImageSelectionDelegate = SelectImage
                });
            }
        }
예제 #2
0
        private async void btnSendAnonymously_Click(object sender, RoutedEventArgs e)
        {
            if (!btnSendAnonymously.IsChecked)
            {
                IsAnonymous = false;

                return;
            }

            var additionalMessage = LocalizationUtils
                                    .GetLocalized("YouMaybeBannedConfirmationMessage");
            var confirmResult = await DialogManager.ShowConfirmationDialog(
                additionalMessage)
                                .ConfigureAwait(true);

            if (confirmResult != MahApps.Metro.Controls.Dialogs.MessageDialogResult.Affirmative)
            {
                btnSendAnonymously.IsChecked = false;

                Keyboard.ClearFocus();

                return;
            }

            IsAnonymous = true;
        }
예제 #3
0
        private static async Task <ResourceDictionary> GetLayoutResourceDictionary(
            FrameworkElement element, string resourceFilePath)
        {
            if (!Uri.TryCreate(resourceFilePath, UriKind.RelativeOrAbsolute, out _))
            {
                var fileTitle     = LocalizationUtils.GetLocalized("FileTitle");
                var notFoundTitle = LocalizationUtils.GetLocalized("NotFoundTitle1");

                await DialogManager.ShowErrorDialog($"{fileTitle} '{resourceFilePath}' {notFoundTitle.ToLower()}")
                .ConfigureAwait(true);

                return(null);
            }

            var elementName = GetElementName(element);

            var layoutDictionary = new ResourceDictionary
            {
                Source = new Uri(resourceFilePath)
            };

            if (!layoutDictionary.Contains("ResourceDictionaryName") ||
                layoutDictionary["ResourceDictionaryName"].ToString()?.StartsWith($"layout-{elementName}-") != true)
            {
                return(null);
            }

            return(layoutDictionary);
        }
        private async void CopyLoginButton_Click(object sender,
                                                 RoutedEventArgs e)
        {
            CopyLoginButton.IsEnabled    = false;
            CopyPasswordButton.IsEnabled = false;

            var login = SettingsManager
                        .PersistentSettings.CurrentUser.Login;

            if (login == null)
            {
                var message = LocalizationUtils
                              .GetLocalized("CopyingToClipboardErrorMessage");

                await DialogManager.ShowErrorDialog(message)
                .ConfigureAwait(true);

                return;
            }

            Clipboard.SetText(login);

            CopyLoginButton.IsEnabled    = true;
            CopyPasswordButton.IsEnabled = true;
        }
        private async void SelectImage_Click(object sender, RoutedEventArgs e)
        {
            if (rbImageRaw.IsChecked == true)
            {
                string title   = LocalizationUtils.GetLocalized("InsertingImageTitle");
                string message = LocalizationUtils.GetLocalized("EnterURL");

                string url = await DialogManager.ShowSinglelineTextDialog(
                    title, message)
                             .ConfigureAwait(true);

                await SelectImage(url)
                .ConfigureAwait(true);
            }
            else if (rbImageTenor.IsChecked == true)
            {
                NavigationController.Instance.RequestPage <TenorSearchPage>(new TenorSearchViewModel
                {
                    OnPicSelect = SelectImage
                });
            }
            else if (rbImageGallery.IsChecked == true)
            {
                NavigationController.Instance.RequestPage <AnonymGallerySearchPage>(new AnonymGallerySearchViewModel
                {
                    OnPicSelect = SelectImage
                });
            }
        }
예제 #6
0
        private async void OnNavButtonClick(object sender,
                                            RoutedEventArgs e)
        {
            if (!(sender is IconButton button))
            {
                return;
            }

            RaiseEvent(new RoutedEventArgs(RedirectRequestedEvent));

            try
            {
                if (button.Information == "Back")
                {
                    NavigationController.Instance.GoBack();
                }
                else if (button.Information == "SettingsFlyout")
                {
                    if (!MainWindow.Instance.SettingsFlyout.IsOpen)
                    {
                        MainWindow.Instance.SettingsFlyout.Show();
                    }
                    else
                    {
                        MainWindow.Instance.SettingsFlyout.Hide();
                    }
                }
                else if (button.Information == "UserProfilePage")
                {
                    if (NavigationController.Instance.PageContent.Content is UserProfilePage page &&
                        page.DataContext is UserProfileViewModel viewModel &&
                        viewModel.CurrentProfileData.Id == SettingsManager.PersistentSettings.CurrentUser.Id)
                    {
                        return;
                    }

                    NavigationController.Instance.RequestPage <UserProfilePage>(new UserProfileViewModel
                    {
                        CurrentProfileData = new ProfileSchema
                        {
                            Id = SettingsManager.PersistentSettings.CurrentUser.Id
                        }
                    });
                }
                else
                {
                    NavigationController.Instance.RequestPage(Type.GetType($"Memenim.Pages.{button.Information}"));
                }

                RaiseEvent(new RoutedEventArgs(RedirectOccurredEvent));
            }
            catch (Exception ex)
            {
                var title = LocalizationUtils.GetLocalized("NavigationErrorTitle");

                await DialogManager.ShowMessageDialog(title, ex.Message)
                .ConfigureAwait(true);
            }
        }
예제 #7
0
        private async void EditNumericAge_Click(object sender, RoutedEventArgs e)
        {
            UserProfileStat element = sender as UserProfileStat;

            BindingExpression binding = element?.GetBindingExpression(UserProfileStat.StatValueProperty);

            if (binding == null)
            {
                return;
            }

            ProfileSchema sourceClass    = (ProfileSchema)binding.ResolvedSource;
            PropertyInfo  sourceProperty = typeof(ProfileSchema).GetProperty(binding.ResolvedSourcePropertyName);

            if (sourceClass == null || sourceProperty == null)
            {
                return;
            }

            string title     = LocalizationUtils.GetLocalized("ProfileEditingTitle");
            string enterName = LocalizationUtils.GetLocalized("EnterTitle");

            int    oldValue = (int)(sourceProperty.GetValue(sourceClass) ?? 0);
            double?value    = await DialogManager.ShowNumericDialog(title,
                                                                    $"{enterName} '{element.StatTitle}'", Convert.ToDouble(oldValue),
                                                                    0.0, 255.0, 1.0, "F0")
                              .ConfigureAwait(true);

            if (value == null)
            {
                return;
            }

            //sourceProperty.SetValue(sourceClass, value.Length == 0 ? null : value);
            sourceProperty.SetValue(sourceClass, Convert.ToInt32(value));

            var request = await UserApi.EditProfile(
                SettingsManager.PersistentSettings.CurrentUser.Token,
                ViewModel.CurrentProfileData)
                          .ConfigureAwait(true);

            if (request.IsError)
            {
                await DialogManager.ShowErrorDialog(request.Message)
                .ConfigureAwait(true);

                sourceProperty.SetValue(sourceClass, oldValue);
            }

            var statBlock = element.TryFindParent <StackPanel>();

            if (statBlock == null)
            {
                return;
            }

            UpdateStatBlock(statBlock);
        }
        public static string GetLocalizedName(this PostCategorySchema source)
        {
            var name =
                source.Name;
            var localizedName = LocalizationUtils
                                .GetLocalized(GetResourceKey(source));

            return(!string.IsNullOrEmpty(localizedName)
                ? localizedName
                : name);
        }
        private async void CopyPasswordButton_Click(object sender,
                                                    RoutedEventArgs e)
        {
            CopyLoginButton.IsEnabled    = false;
            CopyPasswordButton.IsEnabled = false;

            try
            {
                if (SettingsManager.PersistentSettings.CurrentUser.HasRocketPassword())
                {
                    Clipboard.SetText(SettingsManager
                                      .PersistentSettings.CurrentUser.RocketPassword);

                    return;
                }

                var result = await UserApi.GetRocketPassword(
                    SettingsManager.PersistentSettings.CurrentUser.Token)
                             .ConfigureAwait(true);

                if (result.IsError)
                {
                    await DialogManager.ShowErrorDialog(result.Message)
                    .ConfigureAwait(true);

                    return;
                }

                var password =
                    result.Data.Password;

                if (password == null)
                {
                    var message = LocalizationUtils
                                  .GetLocalized("CopyingToClipboardErrorMessage");

                    await DialogManager.ShowErrorDialog(message)
                    .ConfigureAwait(true);

                    return;
                }

                SettingsManager.PersistentSettings.CurrentUser
                .SetRocketPassword(password);

                Clipboard.SetText(
                    password);
            }
            finally
            {
                CopyLoginButton.IsEnabled    = true;
                CopyPasswordButton.IsEnabled = true;
            }
        }
        public static string GetLocalizedName(this PostCategorySchema targetSchema)
        {
            string name =
                targetSchema.Name;
            string localizedName =
                LocalizationUtils.GetLocalized(GetResourceKey(targetSchema));

            return(!string.IsNullOrEmpty(localizedName)
                ? localizedName
                : name);
        }
예제 #11
0
        public static string GetLocalizedName(this Enum targetEnum)
        {
            string name =
                Enum.GetName(targetEnum.GetType(), targetEnum);
            string localizedName =
                LocalizationUtils.GetLocalized(GetResourceKey(targetEnum));

            return(!string.IsNullOrEmpty(localizedName)
                ? localizedName
                : name);
        }
예제 #12
0
        public static string GetLocalizedName(this Enum source)
        {
            var name = Enum.GetName(
                source.GetType(), source);
            var localizedName = LocalizationUtils
                                .GetLocalized(GetResourceKey(source));

            return(!string.IsNullOrEmpty(localizedName)
                ? localizedName
                : name);
        }
예제 #13
0
        private async void UserNameEditClick(object sender, RoutedEventArgs e)
        {
            UserInfoBanner element = this;

            BindingExpression binding = element.txtName.GetBindingExpression(Emoji.Wpf.TextBlock.TextProperty);

            if (binding == null)
            {
                return;
            }

            ProfileSchema sourceClass    = (ProfileSchema)binding.ResolvedSource;
            PropertyInfo  sourceProperty = typeof(ProfileSchema).GetProperty(binding.ResolvedSourcePropertyName);

            if (sourceClass == null || sourceProperty == null)
            {
                return;
            }

            string title     = LocalizationUtils.GetLocalized("ProfileEditingTitle");
            string enterName = LocalizationUtils.GetLocalized("EnterTitle");
            string statName  = LocalizationUtils.GetLocalized("Nickname");

            string oldValue = (string)sourceProperty.GetValue(sourceClass);
            string value    = await DialogManager.ShowSinglelineTextDialog(title,
                                                                           $"{enterName} '{statName}'", oldValue)
                              .ConfigureAwait(true);

            if (value == null)
            {
                return;
            }

            sourceProperty.SetValue(sourceClass, value);

            var request = await UserApi.EditProfile(
                SettingsManager.PersistentSettings.CurrentUser.Token,
                UserProfile)
                          .ConfigureAwait(true);

            if (request.IsError)
            {
                await DialogManager.ShowErrorDialog(request.Message)
                .ConfigureAwait(true);

                sourceProperty.SetValue(sourceClass, oldValue);

                return;
            }

            ProfileUtils.OnNameChanged(this,
                                       new UserNameChangedEventArgs(oldValue, value, UserProfile.Id));
        }
예제 #14
0
        private async void Edit_Click(object sender,
                                      RoutedEventArgs e)
        {
            EditButton.IsEnabled = false;

            try
            {
                if (!CurrentCommentData.User.Id.HasValue || CurrentCommentData.User.Id == -1)
                {
                    return;
                }
                if (CurrentCommentData.User.Id != SettingsManager.PersistentSettings.CurrentUser.Id)
                {
                    return;
                }

                var title   = LocalizationUtils.GetLocalized("EditingCommentTitle");
                var message = LocalizationUtils.GetLocalized("EditingCommentMessage");

                var oldValue = CurrentCommentData.Text;
                var value    = await DialogManager.ShowMultilineTextDialog(
                    title, message, oldValue)
                               .ConfigureAwait(true);

                if (value == null)
                {
                    return;
                }

                var request = await PostApi.EditComment(
                    SettingsManager.PersistentSettings.CurrentUser.Token,
                    CurrentCommentData.Id,
                    value)
                              .ConfigureAwait(true);

                if (request.IsError)
                {
                    await DialogManager.ShowErrorDialog(request.Message)
                    .ConfigureAwait(true);

                    return;
                }

                CurrentCommentData.Text = value;
            }
            finally
            {
                EditButton.IsEnabled = true;
            }
        }
        private async void Edit_Click(object sender, RoutedEventArgs e)
        {
            btnEdit.IsEnabled = false;

            var title   = LocalizationUtils.GetLocalized("EditingPostTitle");
            var message = LocalizationUtils.GetLocalized("EditingPostMessage");

            string oldValue = CurrentPostData.Text;
            string value    = await DialogManager.ShowMultilineTextDialog(
                title, message, oldValue)
                              .ConfigureAwait(true);

            if (value == null)
            {
                btnEdit.IsEnabled = true;
                return;
            }

            PostEditSchema postEditData = new PostEditSchema
            {
                Id             = CurrentPostData.Id,
                Text           = value,
                IsAdult        = CurrentPostData.IsAdult,
                IsAnonymous    = CurrentPostData.IsAnonymous,
                CategoryId     = CurrentPostData.CategoryId,
                Filter         = CurrentPostData.Filter,
                IsHidden       = CurrentPostData.IsHidden,
                IsCommentsOpen = CurrentPostData.IsCommentsOpen,
                Type           = CurrentPostData.Type
            };

            var request = await PostApi.Edit(
                SettingsManager.PersistentSettings.CurrentUser.Token,
                postEditData)
                          .ConfigureAwait(true);

            if (request.IsError)
            {
                await DialogManager.ShowErrorDialog(request.Message)
                .ConfigureAwait(true);

                btnEdit.IsEnabled = true;
                return;
            }

            CurrentPostData.Text = value;

            btnEdit.IsEnabled = true;
        }
예제 #16
0
        private async void SelectAvatarFromUrl_Click(object sender,
                                                     RoutedEventArgs e)
        {
            var title = LocalizationUtils
                        .GetLocalized("InsertingImageTitle");
            var message = LocalizationUtils
                          .GetLocalized("EnterUrl");

            var url = await DialogManager.ShowSinglelineTextDialog(
                title, message)
                      .ConfigureAwait(true);

            await SelectAvatarImage(url)
            .ConfigureAwait(true);
        }
예제 #17
0
        public static string[] GetLocalizedNames(this Enum targetEnum)
        {
            var names          = Enum.GetNames(targetEnum.GetType());
            var localizedNames = new string[names.Length];

            for (var i = 0; i < names.Length; ++i)
            {
                ref var name = ref names[i];

                string localizedName =
                    LocalizationUtils.GetLocalized(GetResourceKey(targetEnum, name));

                localizedNames[i] = !string.IsNullOrEmpty(localizedName)
                    ? localizedName
                    : name;
            }
예제 #18
0
        private async void GeneratePasswordButton_Click(object sender,
                                                        RoutedEventArgs e)
        {
            RegisterButton.IsEnabled         = false;
            GoToLoginButton.IsEnabled        = false;
            LoginTextBox.IsEnabled           = false;
            PasswordTextBox.IsEnabled        = false;
            NicknameTextBox.IsEnabled        = false;
            GeneratePasswordButton.IsEnabled = false;

            try
            {
                var password = GeneratingManager
                               .RandomStringGenerator
                               .GenerateString(20);

                if (password == null)
                {
                    var message = LocalizationUtils
                                  .GetLocalized("CopyingToClipboardErrorMessage");

                    await DialogManager.ShowErrorDialog(message)
                    .ConfigureAwait(true);

                    return;
                }

                PasswordTextBox.Password = password;

                Clipboard.SetText(password);
            }
            catch (Exception ex)
            {
                await DialogManager.ShowErrorDialog(ex.Message)
                .ConfigureAwait(true);
            }
            finally
            {
                RegisterButton.IsEnabled         = !IsRegisterBlocked();
                GoToLoginButton.IsEnabled        = true;
                LoginTextBox.IsEnabled           = true;
                PasswordTextBox.IsEnabled        = true;
                NicknameTextBox.IsEnabled        = true;
                GeneratePasswordButton.IsEnabled = true;
            }
        }
예제 #19
0
        private async void CopyPostText_Click(object sender,
                                              RoutedEventArgs e)
        {
            var text = CurrentPostData.Text;

            if (text == null)
            {
                var message = LocalizationUtils
                              .GetLocalized("CopyingToClipboardErrorMessage");

                await DialogManager.ShowErrorDialog(message)
                .ConfigureAwait(true);

                return;
            }

            Clipboard.SetText(text);
        }
        public static string[] GetLocalizedNames()
        {
            var categories     = PostApi.PostCategories.Values.ToArray();
            var localizedNames = new string[categories.Length];

            for (var i = 0; i < categories.Length; ++i)
            {
                ref var category = ref categories[i];

                string name = category.Name;

                string localizedName =
                    LocalizationUtils.GetLocalized(GetResourceKey(category));

                localizedNames[i] = !string.IsNullOrEmpty(localizedName)
                    ? localizedName
                    : name;
            }
        public static string[] GetLocalizedNames()
        {
            var localizedNames =
                new string[Categories.Length];

            for (var i = 0; i < Categories.Length; ++i)
            {
                ref var category = ref Categories[i];

                var name =
                    category.Name;
                var localizedName = LocalizationUtils
                                    .GetLocalized(GetResourceKey(category));

                localizedNames[i] = !string.IsNullOrEmpty(localizedName)
                    ? localizedName
                    : name;
            }
예제 #22
0
        private async void SelectAvatarFromUrl_Click(object sender, RoutedEventArgs e)
        {
            string title   = LocalizationUtils.GetLocalized("InsertingImageTitle");
            string message = LocalizationUtils.GetLocalized("EnterURL");

            string url = await DialogManager.ShowSinglelineTextDialog(
                title, message)
                         .ConfigureAwait(true);

            if (string.IsNullOrWhiteSpace(url))
            {
                return;
            }

            await ProfileUtils.ChangeAvatar(url)
            .ConfigureAwait(true);

            ViewModel.CurrentProfileData.PhotoUrl = url;
        }
예제 #23
0
        private async void CopyUserLogin_Click(object sender,
                                               RoutedEventArgs e)
        {
            var login =
                ViewModel.CurrentProfileData.Login;

            if (login == null)
            {
                var message = LocalizationUtils
                              .GetLocalized("CopyingToClipboardErrorMessage");

                await DialogManager.ShowErrorDialog(message)
                .ConfigureAwait(true);

                return;
            }

            Clipboard.SetText(login);
        }
예제 #24
0
        private async void CopyImage_Click(object sender,
                                           RoutedEventArgs e)
        {
            var image = Image.Source as BitmapSource;

            if (image == null)
            {
                var message = LocalizationUtils
                              .GetLocalized("CopyingToClipboardErrorMessage");

                await DialogManager.ShowErrorDialog(message)
                .ConfigureAwait(true);

                return;
            }

            Clipboard.SetImage(
                image);
        }
예제 #25
0
        private async void SubmitButton_Click(object sender,
                                              RoutedEventArgs e)
        {
            SubmitButton.IsEnabled = false;

            SubmitButton.Focus();

            try
            {
                var result = await PostApi.Add(
                    SettingsManager.PersistentSettings.CurrentUser.Token,
                    ViewModel.CurrentPostData)
                             .ConfigureAwait(true);

                if (result.IsError)
                {
                    await DialogManager.ShowErrorDialog(result.Message)
                    .ConfigureAwait(true);
                }
                else
                {
                    var message = LocalizationUtils
                                  .GetLocalized("PostSubmittedMessage");

                    await DialogManager.ShowSuccessDialog(message)
                    .ConfigureAwait(true);

                    ClearText();
                    ClearImage();
                }
            }
            catch (Exception ex)
            {
                await DialogManager.ShowErrorDialog(ex.Message)
                .ConfigureAwait(true);
            }
            finally
            {
                SubmitButton.IsEnabled = true;
            }
        }
예제 #26
0
        public async Task LoadMoreComments(int count, int offset)
        {
            var result = await PostApi.GetComments(
                SettingsManager.PersistentSettings.CurrentUser.Token,
                PostId, count, offset)
                         .ConfigureAwait(true);

            if (result.IsError)
            {
                var message = LocalizationUtils.GetLocalized("CouldNotLoadCommentsMessage");

                await DialogManager.ShowErrorDialog(message)
                .ConfigureAwait(true);

                return;
            }

            await AddMoreComments(result.Data)
            .ConfigureAwait(true);

            RaiseEvent(new RoutedEventArgs(OnCommentsUpdated));
        }
예제 #27
0
        public async Task UpdateProfile(int id)
        {
            await ShowLoadingGrid(true)
            .ConfigureAwait(true);

            try
            {
                Interlocked.Increment(ref _profileUpdateWaitingCount);

                await _profileUpdateLock.WaitAsync()
                .ConfigureAwait(true);
            }
            finally
            {
                Interlocked.Decrement(ref _profileUpdateWaitingCount);
            }

            try
            {
                btnEditMode.IsChecked = false;

                if (id < 0)
                {
                    if (!NavigationController.Instance.IsCurrentPage <UserProfilePage>())
                    {
                        return;
                    }

                    NavigationController.Instance.GoBack(true);

                    string message = LocalizationUtils.GetLocalized("UserNotFound");

                    await DialogManager.ShowErrorDialog(message)
                    .ConfigureAwait(true);

                    return;
                }

                var result = await UserApi.GetProfileById(id)
                             .ConfigureAwait(true);

                if (result.IsError)
                {
                    if (!NavigationController.Instance.IsCurrentPage <UserProfilePage>())
                    {
                        return;
                    }

                    NavigationController.Instance.GoBack(true);

                    await DialogManager.ShowErrorDialog(result.Message)
                    .ConfigureAwait(true);

                    return;
                }

                if (result.Data == null)
                {
                    if (!NavigationController.Instance.IsCurrentPage <UserProfilePage>())
                    {
                        return;
                    }

                    NavigationController.Instance.GoBack(true);

                    string message = LocalizationUtils.GetLocalized("UserNotFound");

                    await DialogManager.ShowErrorDialog(message)
                    .ConfigureAwait(true);

                    return;
                }

                ViewModel.CurrentProfileData = result.Data;

                UpdateStatBlock(wpStatBlock1, wpStatBlock2,
                                wpStatBlock3, wpStatBlock4);
            }
            finally
            {
                await Task.Delay(500)
                .ConfigureAwait(true);

                if (_profileUpdateWaitingCount == 0)
                {
                    await ShowLoadingGrid(false)
                    .ConfigureAwait(true);
                }

                _profileUpdateLock.Release();
            }
        }
예제 #28
0
        private async void EditComboBoxSex_Click(object sender, RoutedEventArgs e)
        {
            UserProfileStat element = sender as UserProfileStat;

            BindingExpression binding = element?.GetBindingExpression(UserProfileStat.StatValueProperty);

            if (binding == null)
            {
                return;
            }

            ProfileSchema sourceClass    = (ProfileSchema)binding.ResolvedSource;
            PropertyInfo  sourceProperty = typeof(ProfileSchema).GetProperty(binding.ResolvedSourcePropertyName);

            if (sourceClass == null || sourceProperty == null)
            {
                return;
            }

            string title     = LocalizationUtils.GetLocalized("ProfileEditingTitle");
            string enterName = LocalizationUtils.GetLocalized("EnterTitle");

            ReadOnlyCollection <string> localizedNames =
                new ReadOnlyCollection <string>(UserSexType.Unknown.GetLocalizedNames());

            UserSexType oldValue = (UserSexType)(sourceProperty.GetValue(sourceClass)
                                                 ?? UserSexType.Unknown);
            string valueName = await DialogManager.ShowComboBoxDialog(title,
                                                                      $"{enterName} '{element.StatTitle}'", localizedNames,
                                                                      oldValue.GetLocalizedName())
                               .ConfigureAwait(true);

            if (valueName == null)
            {
                return;
            }

            UserSexType value = UserSexType.Unknown.ParseLocalizedName <UserSexType>(valueName);

            //sourceProperty.SetValue(sourceClass, value.Length == 0 ? null : value);
            sourceProperty.SetValue(sourceClass, value);

            var request = await UserApi.EditProfile(
                SettingsManager.PersistentSettings.CurrentUser.Token,
                ViewModel.CurrentProfileData)
                          .ConfigureAwait(true);

            if (request.IsError)
            {
                await DialogManager.ShowErrorDialog(request.Message)
                .ConfigureAwait(true);

                sourceProperty.SetValue(sourceClass, oldValue);
            }

            var statBlock = element.TryFindParent <StackPanel>();

            if (statBlock == null)
            {
                return;
            }

            UpdateStatBlock(statBlock);
        }
        private async void btnLogin_Click(object sender, RoutedEventArgs e)
        {
            btnLogin.IsEnabled              = false;
            btnGoToRegister.IsEnabled       = false;
            txtLogin.IsEnabled              = false;
            txtPassword.IsEnabled           = false;
            chkRememberMe.IsEnabled         = false;
            btnOpenStoredAccounts.IsEnabled = false;

            try
            {
                var result = await UserApi.Login(
                    txtLogin.Text, txtPassword.Password)
                             .ConfigureAwait(true);

                if (result.IsError)
                {
                    var title = LocalizationUtils.GetLocalized("LoginErrorTitle");

                    await DialogManager.ShowMessageDialog(title, result.Message)
                    .ConfigureAwait(true);

                    return;
                }

                if (chkRememberMe.IsChecked == true)
                {
                    var setUserSuccess = SettingsManager.PersistentSettings.SetUser(
                        txtLogin.Text,
                        result.Data.Token,
                        result.Data.Id,
                        null);

                    if (!setUserSuccess)
                    {
                        return;
                    }

                    if (!SettingsManager.PersistentSettings.SetCurrentUser(
                            txtLogin.Text))
                    {
                        return;
                    }
                }
                else
                {
                    SettingsManager.PersistentSettings.RemoveUser(
                        txtLogin.Text);

                    if (!SettingsManager.PersistentSettings.SetCurrentUserTemporary(
                            txtLogin.Text,
                            result.Data.Token,
                            result.Data.Id))
                    {
                        return;
                    }
                }

                if (NavigationController.Instance.HistoryIsEmpty())
                {
                    NavigationController.Instance.RequestPage <FeedPage>();
                }
                else
                {
                    NavigationController.Instance.GoBack();
                }

                txtLogin.Clear();
                chkRememberMe.IsChecked = false;
            }
            catch (Exception ex)
            {
                await DialogManager.ShowErrorDialog(ex.Message)
                .ConfigureAwait(true);
            }
            finally
            {
                txtPassword.Clear();

                btnLogin.IsEnabled              = !NeedBlockLogin();
                btnGoToRegister.IsEnabled       = true;
                txtLogin.IsEnabled              = true;
                txtPassword.IsEnabled           = true;
                chkRememberMe.IsEnabled         = true;
                btnOpenStoredAccounts.IsEnabled = true;
            }
        }
        public async Task UpdatePost(int id)
        {
            if (id < 1)
            {
                if (!NavigationController.Instance.IsCurrentPage <PostOverlayPage>())
                {
                    return;
                }

                NavigationController.Instance.GoBack(true);

                string message = LocalizationUtils.GetLocalized("PostNotFound");

                await DialogManager.ShowErrorDialog(message)
                .ConfigureAwait(true);

                return;
            }

            ViewModel.CurrentPostData.Id = id;

            var result = await PostApi.GetById(
                SettingsManager.PersistentSettings.CurrentUser.Token,
                ViewModel.CurrentPostData.Id)
                         .ConfigureAwait(true);

            if (result.IsError)
            {
                if (!NavigationController.Instance.IsCurrentPage <PostOverlayPage>())
                {
                    return;
                }

                NavigationController.Instance.GoBack(true);

                await DialogManager.ShowErrorDialog(result.Message)
                .ConfigureAwait(true);

                return;
            }

            if (result.Data == null)
            {
                if (!NavigationController.Instance.IsCurrentPage <PostOverlayPage>())
                {
                    return;
                }

                NavigationController.Instance.GoBack(true);

                string message = LocalizationUtils.GetLocalized("PostNotFound");

                await DialogManager.ShowErrorDialog(message)
                .ConfigureAwait(true);

                return;
            }

            ViewModel.CurrentPostData = result.Data;

            wdgPost.UpdateContextMenus();

            if (ViewModel.SourcePostWidget?.CurrentPostData.Id == ViewModel.CurrentPostData.Id)
            {
                ViewModel.SourcePostWidget?.SetValue(
                    PostWidget.CurrentPostDataProperty,
                    ViewModel.CurrentPostData);
            }
        }