protected override async void OnViewLoaded(object view) { base.OnViewLoaded(view); 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 Acces", "You shall not passed!"); await _window.ShowDialogAsync(_status, null, settings); } else { _status.UpdateMessage("Fatal Exception", ex.Message); await _window.ShowDialogAsync(_status, null, settings); } TryCloseAsync(); } }
protected override async void OnViewLoaded(object view) // Although, it's async, it can be void, because this is an eventhandler { base.OnViewLoaded(view); try { await LoadUsers(); } catch (Exception ex) { // Creating a dialog box starts 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 the Sales Form."); } else { _status.UpdateMessage("Fatal Exception", ex.Message); } _window.ShowDialog(_status, null, settings); // Creating a dialog box ends TryClose(); } }
protected override async void OnViewLoaded(object view) { base.OnViewLoaded(view); 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.Equals("Unauthorized")) { _status.UpdateMessage("Unauthorized Access", "You do not have the permission to interact with the Sales Form."); _window.ShowDialog(_status, null, settings); } else { _status.UpdateMessage("Fatal Exception", ex.Message); _window.ShowDialog(_status, null, settings); } TryClose(); } }
// protected override async void OnViewLoaded(object view) { base.OnViewLoaded(view); try { await LoadUsers(); } catch (Exception ex) { //setting for message box dynamic settings = new ExpandoObject(); settings.WindowStartupLocation = WindowStartupLocation.CenterOwner; settings.ResizeMode = ResizeMode.NoResize; settings.Title = "SystemError"; //this is an option instead of calling it from the constructor. we can have an instance inside your method. //var info = IoC.Get<StatusInforViewModel>(); if (ex.Message == "Unauthorized") { //we have modified that form _status.UpdateMessage("Unauthorized Access", "You do not have permission to interact with the Sales form"); //you need to acknowledge the dialog box first _window.ShowDialog(_status, null, settings); } else { //we have modified that form _status.UpdateMessage("Fatal Exception", ex.Message); //you need to acknowledge the dialog box first _window.ShowDialog(_status, null, settings); } TryClose(); } }
protected override async void OnViewLoaded(object view) { base.OnViewLoaded(view); try { await LoadUsers(); } catch (Exception ex) { dynamic settings = new ExpandoObject(); settings.WindowStartupLocation = WindowStartupLocation.CenterScreen; settings.ResizeMode = ResizeMode.NoResize; settings.Title = "System Error"; //var info = IoC.Get<StatusInfoViewModel>(); if (ex.Message == "Unauthorized") { _status.UpdateMessage("Unauthorized Access", "You do not have permission to interact with the sales form"); await _window.ShowDialogAsync(_status, null, settings); } else { _status.UpdateMessage("Fatal exception", ex.Message); await _window.ShowDialogAsync(_status, null, settings); } await TryCloseAsync(); } }
protected override async void OnViewLoaded(object view) { base.OnViewLoaded(view); try { await LoadProducts(); } catch (Exception ex) { dynamic settings = new ExpandoObject(); settings.WindowStartupLocation = WindowStartupLocation.CenterOwner; settings.ResizeMode = ResizeMode.NoResize; settings.Title = "System Error"; switch (ex.Message) { case "Unauthorized": _status.UpdateMessage("Unauthorized Access", "You donot have permission to interact with the Sales Form"); await _window.ShowDialogAsync(_status, null, settings); break; default: _status.UpdateMessage("Fatal Exception", ex.Message); await _window.ShowDialogAsync(_status, null, settings); break; } await TryCloseAsync(); } }
protected override async void OnViewLoaded(object view) { base.OnViewLoaded(view); 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 ot interact with Sales Form"); } else { _status.UpdateMessage("Fatal Error", $"Unhandling Error: {ex.Message}"); } await _window.ShowDialogAsync(_status, null, settings); await TryCloseAsync(); } }
protected override async void OnViewLoaded(object view) { base.OnViewLoaded(view); try { await LoadProducts(); } catch (Exception ex) { // what do we do here? so that the app doesn't crash when an unathorized user starts this // the StatusInfoViewModel via DI - ideal - just one 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 the Sales Form."); await _window.ShowDialogAsync(_status, null, settings); //_status.UpdateMessage("Second Error/Pop-up", "Second message"); //_window.ShowDialog(_status, null, settings); } else { _status.UpdateMessage("Fatal exception", ex.Message); await _window.ShowDialogAsync(_status, null, settings); } TryCloseAsync(); // W/O StatusInfoViewModel brought in via DI - multiple view models - can be done multiple times if multiple pop-ups or errors are needed //var info = IoC.Get<StatusInfoViewModel>(); } }
protected override async void OnViewLoaded(object view) { base.OnViewLoaded(view); try { await LoadProducts(); } catch (Exception ex) { dynamic settings = new ExpandoObject(); settings.WindowStartupLocation = WindowStartupLocation.CenterOwner; settings.ResizeMode = ResizeMode.NoResize; settings.Title = "System Error"; //// Alternative to Constructor Parameter, create a new copy each time. //var info = IoC.Get<StatusInfoViewModel>(); //info.UpdateMessage("Header Test", "Message Test"); // MVVM Friendly MessageBox: //_status.UpdateMessage("Unauthorized Access", "You do not have permission to interact with the Sales Form."); //_window.ShowDialog(_status, null, settings); // Move into if-statement. if (ex.Message == "Unauthorized") { _status.UpdateMessage("Unauthorized Access", "You do not have permission to interact with the Sales Form."); _window.ShowDialog(_status, null, settings); } else { _status.UpdateMessage("Fatal Exception", ex.Message); _window.ShowDialog(_status, null, settings); } TryClose(); } }
/// <summary> /// Fires an event after page is loaded and await loads a list of products /// </summary> /// <param name="view"></param> protected override async void OnViewLoaded(object view) { base.OnViewLoaded(view); try { await LoadUsers(); } catch (Exception) { dynamic settings = new ExpandoObject(); settings.WindowStartupLocation = WindowStartupLocation.CenterOwner; settings.ResizeMode = ResizeMode.NoResize; settings.Title = "System Message"; _status.UpdateMessage("Unauthorized Access", "You do not have permission to interact with the Sales Form"); _window.ShowDialog(_status, null, settings); TryClose(); } }