This is a snippet of My Code : 1- we should create our filter attribute that inheri ts From ActionFilterAttribute public class WelcomeProgramAttribute : ActionFilterAttribute { //This is the interface responsible of the verification if the customer should have a Gift private readonly IWelcomeGiftCalculationMethod _welcomeGiftCalculationMethod;
public WelcomeProgramAttribute(IWelcomeGiftCalculationMethod welcomeGiftCalculationMethod) { _welcomeGiftCalculationMethod = welcomeGiftCalculationMethod; }
public override async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) { //Checking if the request is coming from our action if (context.ActionDescriptor is ControllerActionDescriptor actionDescriptor && actionDescriptor.ControllerTypeInfo == typeof(ShoppingCartController) && actionDescriptor.ActionName.Equals("Cart")) { // Applying our logic await _welcomeGiftCalculationMethod.CheckWelcomeGiftRules(); await next(); } else { await next(); } } 2-This is the class responsible of registering our filter wich implement INopStartup public class WelcomeProgramStartup : INopStartup {
I just succeed in showing a modal when My Filter is executed : Steps 1 : I transform my plugin to widget plugin by implementing IWidgetPlugin Step2 : i modified the OnActionExecutionAsync like this : public override async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) { if (context.ActionDescriptor is ControllerActionDescriptor actionDescriptor && actionDescriptor.ControllerTypeInfo == typeof(ShoppingCartController) && actionDescriptor.ActionName.Equals("Cart")) { await _welcomeGiftCalculationMethod.CheckWelcomeGiftRules(); var controller = context.Controller as ShoppingCartController; controller.ViewBag.ShowModal = true; await next(); } else { await next(); } } Step3: I added this code to render my widget in a specific widgetZone public Task<IList<string>> GetWidgetZonesAsync() { return Task.FromResult<IList<string>>(new List<string> { PublicWidgetZones.ContentBefore }); }
Step3: i added a view that will show the modal @if (ViewBag.ShowModal ?? false) {