From a5334a71fb99fa577117ffecf8b38321b1aca285 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Sat, 23 Jan 2021 15:50:53 +0300 Subject: [PATCH] Create EventHubPageModel.ShowAlert --- .../src/EventHub.Web/Pages/EventHubPageModel.cs | 15 +++++++++++++-- .../Pages/Organizations/New.cshtml.cs | 12 ++---------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/eventhub/src/EventHub.Web/Pages/EventHubPageModel.cs b/eventhub/src/EventHub.Web/Pages/EventHubPageModel.cs index 6a5cc24..22920eb 100644 --- a/eventhub/src/EventHub.Web/Pages/EventHubPageModel.cs +++ b/eventhub/src/EventHub.Web/Pages/EventHubPageModel.cs @@ -1,4 +1,7 @@ -using EventHub.Localization; +using System; +using EventHub.Localization; +using Microsoft.Extensions.Logging; +using Volo.Abp.AspNetCore.ExceptionHandling; using Volo.Abp.AspNetCore.Mvc.UI.RazorPages; namespace EventHub.Web.Pages @@ -9,5 +12,13 @@ namespace EventHub.Web.Pages { LocalizationResourceType = typeof(EventHubResource); } + + protected void ShowAlert(Exception exception) + { + Logger.LogException(exception); + var errorInfoConverter = LazyServiceProvider.LazyGetRequiredService(); + var errorInfo = errorInfoConverter.Convert(exception, false); + Alerts.Danger(errorInfo.Message); + } } -} \ No newline at end of file +} diff --git a/eventhub/src/EventHub.Web/Pages/Organizations/New.cshtml.cs b/eventhub/src/EventHub.Web/Pages/Organizations/New.cshtml.cs index a679061..10df2af 100644 --- a/eventhub/src/EventHub.Web/Pages/Organizations/New.cshtml.cs +++ b/eventhub/src/EventHub.Web/Pages/Organizations/New.cshtml.cs @@ -4,8 +4,6 @@ using System.Threading.Tasks; using EventHub.Organizations; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Logging; -using Volo.Abp.AspNetCore.ExceptionHandling; using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form; namespace EventHub.Web.Pages.Organizations @@ -17,14 +15,10 @@ namespace EventHub.Web.Pages.Organizations public CreateOrganizationViewModel Organization { get; set; } private readonly IOrganizationAppService _organizationAppService; - private readonly IExceptionToErrorInfoConverter _errorInfoConverter; - public New( - IOrganizationAppService organizationAppService, - IExceptionToErrorInfoConverter errorInfoConverter) + public New(IOrganizationAppService organizationAppService) { _organizationAppService = organizationAppService; - _errorInfoConverter = errorInfoConverter; } public void OnGet() @@ -45,9 +39,7 @@ namespace EventHub.Web.Pages.Organizations } catch (Exception exception) { - Logger.LogException(exception); - var errorInfo = _errorInfoConverter.Convert(exception, false); - Alerts.Danger(errorInfo.Message); + ShowAlert(exception); return Page(); } }