This question is a continuation of my previous post here . Martinho asked me for more information about my system. He has an assumption that there may be a better way to achieve what I'm trying. So, if there is a question, I think I wonder if this is bad? If so, what can be improved and how (I learn best from the illustrations). Thank.
I am developing middleware for an iPhone application at work.
Instead of explicitly calling various objects from the client, developers want to use generic files, where the "Group" returns a JSON string based on the parameter passed. The parameter is the first screen that the user sees when they log in. We call up the dashboard login screen.
So, when the client calls the server method:
Contracts.GroupDto IDashboardService.GetGroupById(string groupId)
{
var obj = GroupRepository.GetGroupById(groupId);
return new Contracts.GroupDto
{
...
};
}
The server uses the GroupRepository GetGroupById method to return the general type of the object:
public static IList<G> GetGroupById<G>(int groupId)
{
DashboardGroupType type = (DashboardGroupType)groupId;
IList<G> result = new List<G>();
var obj = default(G);
switch (type)
{
case DashboardGroupType.Countries:
break;
case DashboardGroupType.Customers:
obj = (G) CustomerRepository.GetAllCustomers();
break;
case DashboardGroupType.Facilities:
obj = (G) FacilityRepository.GetAllFacilities();
break;
case DashboardGroupType.Heiarchy:
break;
case DashboardGroupType.Lines:
break;
case DashboardGroupType.Regions:
obj = (G) CustomerRepository.GetRegionsHavingCustomers();
break;
case DashboardGroupType.States:
obj = (G) CustomerRepository.GetStatesHavingCustomers();
break;
case DashboardGroupType.Tanks:
break;
default:
break;
}
result.Add(obj);
return result;
}
The return type of the object is based on the parameter passed to GetGroupById. For example, if the value is 1, the method scans the DashboardGroupType enumeration:
and passes parameter 1, the server scans the following enumeration:
public enum DashboardGroupType
{
Countries = 0,
Regions = 1,
Customers = 2,
Facilities = 3,
Lines = 4,
Tanks = 5,
States = 6,
Heiarchy = 7
}
and returns a list of regions of type IEnumerable to the calling client.
( IList GetGroupById (int groupId)? , .
.