I'm working on an Asp.net core 5
project targeted .Net 5
, I try to create an Action filter
that will receive a property name, and he will recieve a TEntity
generic type (represent the table to select from) and catch the submitted model
and get the property value from it (model
), this Action Filter
will look in database if a record already has the same value in the past property inside the table passed in TEntity
.
My Action filter:
public class RecordShouldNotExistFilter<TEntity>:IActionFilter where TEntity : class
{
private readonly AppDbContext _dbContext;
public string PropertyToBeChecked { get; set; }
public RecordShouldNotExistFilter( AppDbContext dbContext )
{
_dbContext = dbContext;
}
public void OnActionExecuting( ActionExecutingContext context )
{
// Some logic here that uses the PropertyToBeChecked's value
}
}
public void OnActionExecuted( ActionExecutedContext context )
{
}
}
The problem:
When I try to apply the filter on my action I don't know how to pass the PropertyToBeChecked
value.
I paused here :
[TypeFilter(typeof(RecordShouldNotExistFilter<PedagogicalSequence>))]
public async Task<IActionResult> Create( PedagogicalSequenceModel model )
{
}
The question :
How can I pass the PropertyToBeChecked
value ? or how to achieve my object with another way ? except using Action
parameters