Retail_manager/RMWPFUserInterface/ViewModels/ShellViewModel.cs

70 lines
1.8 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;
using RMWPFInterfaceLibrary.Api;
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;
private IAPIHelper _apiHelper;
public ShellViewModel(IEventAggregator events, SalesViewModel salesVM,
SimpleContainer container, ILoggedInUserModel user, IAPIHelper apiHelper)
2022-07-08 16:27:24 +02:00
{
_salesVM = salesVM;
_events = events;
2022-07-27 16:41:36 +02:00
_user = user;
_apiHelper = apiHelper;
_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.ResetUserModel();
_apiHelper.LogOffUser();
2022-07-27 16:41:36 +02:00
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
}
}
}