We have 1000 small lookup table editor in database. Each having few rows maximum. Instead of writing 1000 Apis, services, angular proxies we created an Object lookup viewer/editor in grid cell. Small Tables like ProductCodeLookup, AddressType, SupplyCategory, FurnitureType
Also there is API Operator from a webpage, where people can See and Add Rows to the lookup Tables. (see picture link below) The question came up, how do we dynamically apply Model Validation on the Request Object in API?
Front end validation is on Angular
However, for C#, we want all LookupIds and int category to be 1-100 max. String request members to be 255 characters max. Emails to be in @email regex format etc. We may not know what Object request looks like at runtime, until table is selected.
[HttpPost("[Action]")]
public void AddObject(List<object> addListRequest, string lookupTableName)
{
foreach (var addItem in addListRequest)
{
var addItemCast = addItem.ConvertObjectToTypeWithSerialization(atype);
context.Add(addItemCast);
}
}
This answer for older Net MVC, we are using Net Core 3 API. Dynamically apply validation rules at runtime with ASP.NET MVC 4
Thought there is method to conduct this with new library.