Add dialog box and check permissions
Checks if user if authorized if not message box poppes up
This commit is contained in:
parent
35c5e1af28
commit
7c40488938
@ -91,6 +91,7 @@
|
|||||||
<Compile Include="ViewModels\LoginViewModel.cs" />
|
<Compile Include="ViewModels\LoginViewModel.cs" />
|
||||||
<Compile Include="ViewModels\SalesViewModel.cs" />
|
<Compile Include="ViewModels\SalesViewModel.cs" />
|
||||||
<Compile Include="ViewModels\ShellViewModel.cs" />
|
<Compile Include="ViewModels\ShellViewModel.cs" />
|
||||||
|
<Compile Include="ViewModels\StatusInfoViewModel.cs" />
|
||||||
<Compile Include="Views\LoginView.xaml.cs">
|
<Compile Include="Views\LoginView.xaml.cs">
|
||||||
<DependentUpon>LoginView.xaml</DependentUpon>
|
<DependentUpon>LoginView.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
@ -104,6 +105,9 @@
|
|||||||
<DependentUpon>App.xaml</DependentUpon>
|
<DependentUpon>App.xaml</DependentUpon>
|
||||||
<SubType>Code</SubType>
|
<SubType>Code</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="Views\StatusInfoView.xaml.cs">
|
||||||
|
<DependentUpon>StatusInfoView.xaml</DependentUpon>
|
||||||
|
</Compile>
|
||||||
<Page Include="Views\LoginView.xaml">
|
<Page Include="Views\LoginView.xaml">
|
||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
@ -116,6 +120,10 @@
|
|||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
</Page>
|
</Page>
|
||||||
|
<Page Include="Views\StatusInfoView.xaml">
|
||||||
|
<SubType>Designer</SubType>
|
||||||
|
<Generator>MSBuild:Compile</Generator>
|
||||||
|
</Page>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Properties\AssemblyInfo.cs">
|
<Compile Include="Properties\AssemblyInfo.cs">
|
||||||
|
@ -7,9 +7,11 @@ using RMWPFUserInterface.Models;
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
|
using System.Dynamic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows;
|
||||||
|
|
||||||
namespace RMWPFUserInterface.ViewModels
|
namespace RMWPFUserInterface.ViewModels
|
||||||
{
|
{
|
||||||
@ -19,21 +21,48 @@ namespace RMWPFUserInterface.ViewModels
|
|||||||
IConfigHelper _configHelper;
|
IConfigHelper _configHelper;
|
||||||
ISaleEndPoint _saleEndPoint;
|
ISaleEndPoint _saleEndPoint;
|
||||||
IMapper _mapper;
|
IMapper _mapper;
|
||||||
|
private readonly StatusInfoViewModel _status;
|
||||||
|
private readonly IWindowManager _window;
|
||||||
|
|
||||||
public SalesViewModel(IProductEndPoint productEndPoint, IConfigHelper configHelper,
|
public SalesViewModel(IProductEndPoint productEndPoint, IConfigHelper configHelper,
|
||||||
ISaleEndPoint saleEndPoint, IMapper mapper)
|
ISaleEndPoint saleEndPoint, IMapper mapper, StatusInfoViewModel status, IWindowManager window)
|
||||||
{
|
{
|
||||||
_productEndPoint = productEndPoint;
|
_productEndPoint = productEndPoint;
|
||||||
_configHelper = configHelper;
|
_configHelper = configHelper;
|
||||||
_saleEndPoint = saleEndPoint;
|
_saleEndPoint = saleEndPoint;
|
||||||
_mapper = mapper;
|
_mapper = mapper;
|
||||||
|
_status = status;
|
||||||
|
_window = window;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override async void OnViewLoaded(object view)
|
protected override async void OnViewLoaded(object view)
|
||||||
{
|
{
|
||||||
base.OnViewLoaded(view);
|
base.OnViewLoaded(view);
|
||||||
|
try
|
||||||
|
{
|
||||||
await LoadProducts();
|
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()
|
private async Task LoadProducts()
|
||||||
{
|
{
|
||||||
|
28
RMWPFUserInterface/ViewModels/StatusInfoViewModel.cs
Normal file
28
RMWPFUserInterface/ViewModels/StatusInfoViewModel.cs
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
16
RMWPFUserInterface/Views/StatusInfoView.xaml
Normal file
16
RMWPFUserInterface/Views/StatusInfoView.xaml
Normal 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>
|
28
RMWPFUserInterface/Views/StatusInfoView.xaml.cs
Normal file
28
RMWPFUserInterface/Views/StatusInfoView.xaml.cs
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user