2022-07-04 18:48:43 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
2022-07-23 17:09:13 +02:00
|
|
|
|
using System.Threading;
|
2022-07-04 18:48:43 +02:00
|
|
|
|
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;
|
2022-07-23 17:09:13 +02:00
|
|
|
|
using RMWPFUserInterface.EventModels;
|
2022-07-04 18:48:43 +02:00
|
|
|
|
|
|
|
|
|
namespace RMWPFUserInterface.ViewModels
|
|
|
|
|
{
|
2022-07-23 17:09:13 +02:00
|
|
|
|
public class ShellViewModel : Conductor<Object>, IHandle<LogOnEvent>
|
2022-07-04 18:48:43 +02:00
|
|
|
|
{
|
2022-07-23 17:09:13 +02:00
|
|
|
|
private IEventAggregator _events;
|
|
|
|
|
private SalesViewModel _salesVM;
|
2022-07-27 16:41:36 +02:00
|
|
|
|
private ILoggedInUserModel _user;
|
2022-07-23 17:09:13 +02:00
|
|
|
|
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
|
|
|
|
{
|
2022-07-23 17:09:13 +02:00
|
|
|
|
_salesVM = salesVM;
|
|
|
|
|
_events = events;
|
2022-07-27 16:41:36 +02:00
|
|
|
|
_user = user;
|
2022-07-23 17:09:13 +02:00
|
|
|
|
|
|
|
|
|
_events.SubscribeOnUIThread(this);
|
|
|
|
|
|
2022-07-24 00:08:22 +02:00
|
|
|
|
ActivateItemAsync(IoC.Get<LoginViewModel>());
|
2022-07-23 17:09:13 +02:00
|
|
|
|
}
|
2022-07-27 16:41:36 +02:00
|
|
|
|
public bool IsLoggedIn
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
bool output = false;
|
2022-07-23 17:09:13 +02:00
|
|
|
|
|
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>());
|
|
|
|
|
|
|
|
|
|
}
|
2022-07-23 17:09:13 +02:00
|
|
|
|
public Task HandleAsync(LogOnEvent message, CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
ActivateItemAsync(_salesVM);
|
2022-07-27 16:41:36 +02:00
|
|
|
|
NotifyOfPropertyChange(() => IsLoggedIn);
|
2022-07-23 17:09:13 +02:00
|
|
|
|
return Task.CompletedTask;
|
2022-07-08 16:27:24 +02:00
|
|
|
|
}
|
2022-07-04 18:48:43 +02:00
|
|
|
|
}
|
|
|
|
|
}
|