Retail_manager/RMWPFUserInterface/ViewModels/ShellViewModel.cs

65 lines
1.7 KiB
C#
Raw Normal View History

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