I've been working on an application that everytime you register, modify, cancel, delete ,etc... something, a notification has to be sent to a user(if it is configured) so i'm planning to do this by saving a unique identifier of the proccess on the database and then check if the notification is configured with an id, a proccess and the unique identifier and after all this send the notification.
To do this i had this in mind... this on the controller
   [NotificationFilter(id=10,proccess="Excecution") ]
   public Register(Entity entity,Guid uid){
   }
This on the ActionFilter class
public class NotificationFilter : ActionFilterAttribute
{
    public int id{ get; set; }
    public string proccess{ get; set; }
    public override void OnActionExecuted(ActionExecutedContext filterContext)
    {
         dosomething(id,name,uid)
    }
}
but I want to know if there is a way to get the uid parameter of my Register action into the OnActionExecuted method.
Taking Neel Bhatt answer.. I did something like this to make this work.
public class NotificationFilter : ActionFilterAttribute
{
    public int _id;
    public string _proccess;
    public Guid _uid; 
    public NotificationFilter(int id,string proccess)
    {
        _id= id;
        _proccess = proccess;
    }
    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
         var val = filterContext.ActionParameters["uid"];
        _uid = (Guid)val;
    }
    public override void OnActionExecuted(ActionExecutedContext filterContext)
    {
         var uid = _uid;
         dosomething(id,name,uid)
    }
}
This works for me, and hope could be helpfull to someone else.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With