Retail_manager/RMWPFUserInterface/ViewModels/ShellViewModel.cs
s459315 5c2b914884 Fix Log Off Bug
fixes the bug where header was not being cleared on log off
2022-07-30 14:21:25 +02:00

70 lines
1.8 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Caliburn.Micro;
using RMWPFInterfaceLibrary.Api;
using RMWPFInterfaceLibrary.Models;
using RMWPFUserInterface.EventModels;
namespace RMWPFUserInterface.ViewModels
{
public class ShellViewModel : Conductor<Object>, IHandle<LogOnEvent>
{
private IEventAggregator _events;
private SalesViewModel _salesVM;
private ILoggedInUserModel _user;
private IAPIHelper _apiHelper;
public ShellViewModel(IEventAggregator events, SalesViewModel salesVM,
SimpleContainer container, ILoggedInUserModel user, IAPIHelper apiHelper)
{
_salesVM = salesVM;
_events = events;
_user = user;
_apiHelper = apiHelper;
_events.SubscribeOnUIThread(this);
ActivateItemAsync(IoC.Get<LoginViewModel>());
}
public bool IsLoggedIn
{
get
{
bool output = false;
if (string.IsNullOrWhiteSpace(_user.Token) == false)
{
output = true;
}
return output;
}
}
public void ExitApplication()
{
TryCloseAsync();
}
public void LogOut()
{
_user.ResetUserModel();
_apiHelper.LogOffUser();
NotifyOfPropertyChange(() => IsLoggedIn);
ActivateItemAsync(IoC.Get<LoginViewModel>());
}
public Task HandleAsync(LogOnEvent message, CancellationToken cancellationToken)
{
ActivateItemAsync(_salesVM);
NotifyOfPropertyChange(() => IsLoggedIn);
return Task.CompletedTask;
}
}
}