Пример #1
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);
        }
        private async void StackPanel_Loaded(object sender, RoutedEventArgs e)
        {
            var res = await UserApi.GetProfileById(UserID);

            if (!res.IsError)
            {
                UserProfile = res.Data;
            }
        }
Пример #3
0
        public UserProfileViewModel()
            : base(typeof(UserProfilePage))
        {
            _currentProfileData = new ProfileSchema
            {
                Id = -1
            };

            CurrentProfileData.PropertyChanged += CurrentProfileData_PropertyChanged;
        }
Пример #4
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));
        }
Пример #5
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);
        }
Пример #6
0
 public static Task <ApiResponse> EditProfile(string token, ProfileSchema profileData)
 {
     return(ApiRequestEngine.ExecuteAnonymRequestJson("users/profile/set", profileData, token));
 }