mirror of
https://gitlab.com/fabinfra/fabaccess/borepin.git
synced 2025-03-12 23:01:52 +01:00
99 lines
3.0 KiB
C#
99 lines
3.0 KiB
C#
using Borepin.Base;
|
|
using Prism.Commands;
|
|
using Prism.Navigation;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Input;
|
|
using FabAccessAPI.Schema;
|
|
using Borepin.Model;
|
|
using Prism.Services;
|
|
using Borepin.Service;
|
|
using Borepin.Base.Exceptions;
|
|
using Capnp.Rpc;
|
|
using System;
|
|
using Borepin.ViewModel;
|
|
using System.Collections.Generic;
|
|
using NaturalSort.Extension;
|
|
using System.Linq;
|
|
using Prism.Services.Dialogs;
|
|
using Xamarin.Forms;
|
|
|
|
namespace Borepin.PageModel
|
|
{
|
|
public class ProfilePageModel : ConnectionModelBase
|
|
{
|
|
#region Contructors
|
|
public ProfilePageModel(INavigationService navigationService, IPageDialogService pageDialogService, IAPIService apiService) : base(navigationService, pageDialogService, apiService)
|
|
{
|
|
UpdatePasswordCommand = new DelegateCommand(UpdatePasswordCommandExecute);
|
|
}
|
|
#endregion
|
|
|
|
#region Data
|
|
public override Task LoadInstance(object instance)
|
|
{
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public override async Task LoadAPIData()
|
|
{
|
|
_UserItem = new UserVisualize(await _API.Session.UserSystem.Info.GetUserSelf().ConfigureAwait(false));
|
|
_UserItem.LoadData();
|
|
}
|
|
#endregion
|
|
|
|
#region Fields
|
|
|
|
private UserVisualize _UserItem;
|
|
public UserVisualize UserItem
|
|
{
|
|
get => _UserItem;
|
|
set => SetProperty(ref _UserItem, value);
|
|
}
|
|
|
|
private string _OldPassword = null;
|
|
public string OldPassword
|
|
{
|
|
get => _OldPassword;
|
|
set => SetProperty(ref _OldPassword, value);
|
|
}
|
|
|
|
private string _NewPassword = null;
|
|
public string NewPassword
|
|
{
|
|
get => _NewPassword;
|
|
set => SetProperty(ref _NewPassword, value);
|
|
}
|
|
#endregion
|
|
|
|
#region Commands
|
|
private ICommand _UpdatePasswordCommand;
|
|
public ICommand UpdatePasswordCommand
|
|
{
|
|
get => _UpdatePasswordCommand;
|
|
set => SetProperty(ref _UpdatePasswordCommand, value);
|
|
}
|
|
|
|
public async void UpdatePasswordCommandExecute()
|
|
{
|
|
IsBusy = true;
|
|
if (_API.IsConnected)
|
|
{
|
|
try
|
|
{
|
|
if(OldPassword != null && OldPassword != string.Empty && NewPassword != null && NewPassword != string.Empty)
|
|
{
|
|
User self = await _API.Session.UserSystem.Info.GetUserSelf().ConfigureAwait(false);
|
|
await self.Manage.Pwd(OldPassword, NewPassword).ConfigureAwait(false);
|
|
}
|
|
}
|
|
catch (RpcException exception) when (string.Equals(exception.Message, "RPC connection is broken. Task would never return.", StringComparison.Ordinal))
|
|
{
|
|
Log.Debug("RPC Connection Loss");
|
|
}
|
|
}
|
|
IsBusy = false;
|
|
}
|
|
#endregion
|
|
}
|
|
}
|