From 2ed8e331ec9d421cedb66383702be756df8afedc Mon Sep 17 00:00:00 2001 From: s459315 Date: Wed, 27 Jul 2022 16:41:36 +0200 Subject: [PATCH] Overall Bug Fixes --- .../Models/ILoggedInUserModel.cs | 1 + .../Models/LoggedInUserModel.cs | 10 ++++++ .../ViewModels/SalesViewModel.cs | 18 +++++++++- .../ViewModels/ShellViewModel.cs | 34 +++++++++++++++++-- RMWPFUserInterface/Views/ShellView.xaml | 6 ++-- 5 files changed, 63 insertions(+), 6 deletions(-) diff --git a/RMWPFInterfaceLibrary/Models/ILoggedInUserModel.cs b/RMWPFInterfaceLibrary/Models/ILoggedInUserModel.cs index 73328b5..aac84b7 100644 --- a/RMWPFInterfaceLibrary/Models/ILoggedInUserModel.cs +++ b/RMWPFInterfaceLibrary/Models/ILoggedInUserModel.cs @@ -10,5 +10,6 @@ namespace RMWPFInterfaceLibrary.Models string Id { get; set; } string LastName { get; set; } string Token { get; set; } + void LogOffUser(); } } \ No newline at end of file diff --git a/RMWPFInterfaceLibrary/Models/LoggedInUserModel.cs b/RMWPFInterfaceLibrary/Models/LoggedInUserModel.cs index 0d163de..0addb10 100644 --- a/RMWPFInterfaceLibrary/Models/LoggedInUserModel.cs +++ b/RMWPFInterfaceLibrary/Models/LoggedInUserModel.cs @@ -14,5 +14,15 @@ namespace RMWPFInterfaceLibrary.Models public string LastName { get; set; } public string EmailAddress { get; set; } public DateTime CreatedDate { get; set; } + + public void LogOffUser() + { + Token = ""; + Id = ""; + FirstName = ""; + LastName = ""; + EmailAddress = ""; + CreatedDate = DateTime.MinValue; + } } } diff --git a/RMWPFUserInterface/ViewModels/SalesViewModel.cs b/RMWPFUserInterface/ViewModels/SalesViewModel.cs index b9ec4e0..9d26761 100644 --- a/RMWPFUserInterface/ViewModels/SalesViewModel.cs +++ b/RMWPFUserInterface/ViewModels/SalesViewModel.cs @@ -41,7 +41,20 @@ namespace RMWPFUserInterface.ViewModels var products = _mapper.Map>(products_lsit); Products = new BindingList(products); } + private async Task ResetSalesViewModel() + { + Cart = new BindingList(); + // TODO - Add clearing selectedCartItem if that does not clear it + await LoadProducts(); + + NotifyOfPropertyChange(() => SubTotal); + NotifyOfPropertyChange(() => Tax); + NotifyOfPropertyChange(() => Total); + NotifyOfPropertyChange(() => CanCheckOut); + NotifyOfPropertyChange(() => CanAddToCart); + + } private BindingList _products; public BindingList Products @@ -200,7 +213,7 @@ namespace RMWPFUserInterface.ViewModels bool output = false; // Make sure something is selected - if (SelectedCartItem != null && SelectedCartItem?.Product.QuantityInStock > 0) + if (SelectedCartItem != null && SelectedCartItem?.QuantityInCart > 0) { output = true; } @@ -225,6 +238,7 @@ namespace RMWPFUserInterface.ViewModels NotifyOfPropertyChange(() => Tax); NotifyOfPropertyChange(() => Total); NotifyOfPropertyChange(() => CanCheckOut); + NotifyOfPropertyChange(() => CanAddToCart); } public bool CanCheckOut @@ -256,6 +270,8 @@ namespace RMWPFUserInterface.ViewModels } await _saleEndPoint.PostSale(sale); + + await ResetSalesViewModel(); } } } diff --git a/RMWPFUserInterface/ViewModels/ShellViewModel.cs b/RMWPFUserInterface/ViewModels/ShellViewModel.cs index 4b52c4f..073f09e 100644 --- a/RMWPFUserInterface/ViewModels/ShellViewModel.cs +++ b/RMWPFUserInterface/ViewModels/ShellViewModel.cs @@ -5,6 +5,7 @@ using System.Text; using System.Threading; using System.Threading.Tasks; using Caliburn.Micro; +using RMWPFInterfaceLibrary.Models; using RMWPFUserInterface.EventModels; namespace RMWPFUserInterface.ViewModels @@ -13,21 +14,50 @@ namespace RMWPFUserInterface.ViewModels { private IEventAggregator _events; private SalesViewModel _salesVM; + private ILoggedInUserModel _user; public ShellViewModel(IEventAggregator events, SalesViewModel salesVM, - SimpleContainer container) + SimpleContainer container, ILoggedInUserModel user) { _salesVM = salesVM; _events = events; + _user = user; _events.SubscribeOnUIThread(this); ActivateItemAsync(IoC.Get()); } + 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.LogOffUser(); + + NotifyOfPropertyChange(() => IsLoggedIn); + ActivateItemAsync(IoC.Get()); + + } public Task HandleAsync(LogOnEvent message, CancellationToken cancellationToken) { ActivateItemAsync(_salesVM); - + NotifyOfPropertyChange(() => IsLoggedIn); return Task.CompletedTask; } } diff --git a/RMWPFUserInterface/Views/ShellView.xaml b/RMWPFUserInterface/Views/ShellView.xaml index 99e99a5..1697e2f 100644 --- a/RMWPFUserInterface/Views/ShellView.xaml +++ b/RMWPFUserInterface/Views/ShellView.xaml @@ -9,10 +9,10 @@ - + - - + +