Hi All,
I am struggling a bit to figure this one out.
I'm working on an ASP.NET MVC project, using LINQ to SQL for my data layer. The database consists of 10 or so different "exceptions" tables, e.g. "Exceptions.LADM", "Exceptions.USB", "Exceptions.GPO". Basically these tables are tracking user+machine information for relaxation of various security procedures.
My LINQ to SQL model has been generated. I have different classes for each table available to me. However, I am not sure how to use them in controller without having to generate separate Controller Actions for each exception type. For List
action, I want to do something like this:
// Example Request: /Exceptions/List/ladm
// Routing: Controller = "Exceptions", Action = "List", type = "ladm"
// Controller Action:
public ActionResult List(string type)
{
string viewname = "List-" + type; // refer to "List-ladm" view.
if(type == "ladm")
{
var items = _repository.ListAllLADMExceptions();
}
return View(viewname, items);
}
My repository implements ListAll<XXXXXX>Exceptions
methods for each table. Is there a way to avoid 10 different if/else statements? It looks ugly and I'm sure there is a better way that I cannot think of. May be I'm approaching it from incorrect angle.
Any suggestions would be welcomed.
Thanks.