Add dialog box and check permissions

Checks if user if authorized if not message box poppes up
This commit is contained in:
s459315 2022-08-06 17:04:09 +02:00
parent 35c5e1af28
commit 7c40488938
5 changed files with 111 additions and 2 deletions

View File

@ -91,6 +91,7 @@
<Compile Include="ViewModels\LoginViewModel.cs" />
<Compile Include="ViewModels\SalesViewModel.cs" />
<Compile Include="ViewModels\ShellViewModel.cs" />
<Compile Include="ViewModels\StatusInfoViewModel.cs" />
<Compile Include="Views\LoginView.xaml.cs">
<DependentUpon>LoginView.xaml</DependentUpon>
</Compile>
@ -104,6 +105,9 @@
<DependentUpon>App.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="Views\StatusInfoView.xaml.cs">
<DependentUpon>StatusInfoView.xaml</DependentUpon>
</Compile>
<Page Include="Views\LoginView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
@ -116,6 +120,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\StatusInfoView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs">

View File

@ -7,9 +7,11 @@ using RMWPFUserInterface.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Dynamic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace RMWPFUserInterface.ViewModels
{
@ -19,20 +21,47 @@ namespace RMWPFUserInterface.ViewModels
IConfigHelper _configHelper;
ISaleEndPoint _saleEndPoint;
IMapper _mapper;
private readonly StatusInfoViewModel _status;
private readonly IWindowManager _window;
public SalesViewModel(IProductEndPoint productEndPoint, IConfigHelper configHelper,
ISaleEndPoint saleEndPoint, IMapper mapper)
ISaleEndPoint saleEndPoint, IMapper mapper, StatusInfoViewModel status, IWindowManager window)
{
_productEndPoint = productEndPoint;
_configHelper = configHelper;
_saleEndPoint = saleEndPoint;
_mapper = mapper;
_status = status;
_window = window;
}
protected override async void OnViewLoaded(object view)
{
base.OnViewLoaded(view);
await LoadProducts();
try
{
await LoadProducts();
}
catch (Exception ex)
{
dynamic settings = new ExpandoObject();
settings.WindowStartUpLocation = WindowStartupLocation.CenterOwner;
settings.ResizeMode = ResizeMode.NoResize;
settings.Title = "System Error";
if (ex.Message == "Unauthorized")
{
_status.UpdateMessage("Unauthorized Access", "You do not have permission to interact with Sales Form.");
_window.ShowDialogAsync(_status, null, settings);
}
else
{
_status.UpdateMessage("Fatal exception", ex.Message);
_window.ShowDialogAsync(_status, null, settings);
}
TryCloseAsync();
}
}
private async Task LoadProducts()

View File

@ -0,0 +1,28 @@
using Caliburn.Micro;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RMWPFUserInterface.ViewModels
{
public class StatusInfoViewModel : Screen
{
public string Header { get; private set; }
public string Message { get; private set; }
public void UpdateMessage(string header, string message)
{
Header = header;
Message = message;
NotifyOfPropertyChange(() => Header);
NotifyOfPropertyChange(() => Message);
}
public void Close()
{
TryCloseAsync();
}
}
}

View File

@ -0,0 +1,16 @@
<UserControl x:Class="RMWPFUserInterface.Views.StatusInfoView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:RMWPFUserInterface.Views"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<StackPanel Orientation="Vertical">
<TextBlock x:Name="Header" FontSize="20" FontWeight="Bold" Margin="10" />
<TextBlock x:Name="Message" FontSize="18" Margin="10" />
<Button x:Name="Close" Padding="10" Margin="20">Close</Button>
</StackPanel>
</Grid>
</UserControl>

View File

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace RMWPFUserInterface.Views
{
/// <summary>
/// Interaction logic for StatusInfoView.xaml
/// </summary>
public partial class StatusInfoView : UserControl
{
public StatusInfoView()
{
InitializeComponent();
}
}
}