Skip to content

Commit

Permalink
Refactor BaseController by removing unused event notification logic a…
Browse files Browse the repository at this point in the history
…nd simplifying method calls (#531)
  • Loading branch information
KrzysztofPajak authored Nov 24, 2024
1 parent dfb7896 commit a23f2ff
Showing 1 changed file with 1 addition and 28 deletions.
29 changes: 1 addition & 28 deletions src/Web/Grand.Web.Common/Controllers/BaseController.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
using Grand.Business.Core.Interfaces.Common.Localization;
using Grand.Infrastructure.Models;
using Grand.Web.Common.DataSource;
using Grand.Web.Common.Events;
using Grand.Web.Common.Extensions;
using Grand.Web.Common.Filters;
using Grand.Web.Common.Page;
using MediatR;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
Expand All @@ -21,18 +18,6 @@ namespace Grand.Web.Common.Controllers;
[CustomerActivity]
public abstract class BaseController : Controller
{
public override async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
{
// event notification before execute
var mediator = context.HttpContext.RequestServices.GetService<IMediator>();
await mediator.Publish(new ActionExecutingContextNotification(context, true));

await next();

//event notification after execute
await mediator.Publish(new ActionExecutingContextNotification(context, false));
}

#region Notifications

/// <summary>
Expand Down Expand Up @@ -197,8 +182,7 @@ protected virtual async Task AddLocales<TLocalizedModelLocal>(ILanguageService l
var locale = Activator.CreateInstance<TLocalizedModelLocal>();
locale.LanguageId = language.Id;

if (configure != null)
configure.Invoke(locale, locale.LanguageId);
configure?.Invoke(locale, locale.LanguageId);

locales.Add(locale);
}
Expand All @@ -216,16 +200,5 @@ protected IActionResult AccessDeniedView()
{
return RedirectToAction("AccessDenied", "Home");
}

/// <summary>
/// Access denied json data for kendo grid
/// </summary>
/// <returns>Access denied json data</returns>
protected JsonResult AccessDeniedKendoGridJson()
{
var translationService = HttpContext.RequestServices.GetRequiredService<ITranslationService>();
return ErrorForKendoGridJson(translationService.GetResource("Admin.AccessDenied.Description"));
}

#endregion
}

0 comments on commit a23f2ff

Please sign in to comment.