I need your help. I got test project in which I'm returning HTML table
full of employees information from DB table
based on their roles.Currently there are 3 roles : Admin , Office Director and Delivery Manager.Admin can see all info ,Office director all employees from his office, and delivery manager all employees from his department regardless of office.Also employee can be office director at more than one office, he can be delivery manager at more than one department and last employee can be both delivery manager and office director.I didn't want to use any design pattern
(strategy,builder,factory)
because I've read that I should use it if there is more than 15-20 roles. I have this simple solution , but I'm not satisfied with it , because if in future I want to add another role , for example project manager , who can see something based on different query , it would be harder to implement that role in this solution , and code will be hard to maintain (especially if I add 2 or 3 roles, that is the maximum that I expect in future).
If anyone is kind to look at code and give me his thoughts or idea how can I refactor my code without using of design patterns, so it would be maintainable and opened for adding new roles(one or two).
There is another method which is returning list of employee roles List<string> Positions
. Then , based on roles, here is main part of business logic
in my method I want you to look at and make suggestion.
public List<EmployeeRecord> GetListOfEmployeeInfo(Employee emp)
{
List<EmployeeRecord> records = new List<EmployeeRecord>();
if (emp.Positions.Contains("Admin"))
{// stored procedure that retrieves all info,
//there is no need to check if employee has another role, because as admin he can see everything}
else
{
if(emp.Positions.Contains("OfficeDirector") && emp.Positions.Contains("DeliveryManager"))
{
//stored procedure that returns distinct data for these 2 roles
}
else
{
if (emp.Positions.Contains("OfficeDirector"))
{//recursive method that will retrieve all info in case employee is office director in more than 1 office, and stored procedure}
if (emp.Positions.Contains("DeliveryManager"))
{//recursive method that will retrieve all info in case employee is delivery manager on more than 1 department, and stored procedure}
}
}
// ... further code to populate list of records etc
}
Thank you!
Aucun commentaire:
Enregistrer un commentaire