//We could make a separate interface and class with different implementations of how we want to handle the response. This would be like a strategy design pattern //For simplicity and since there is only one way to implement this right now, I just left the logic in here. static void handleBusinessLogicResponse(GetUserPreferencesResult response) { switch(response.ReturnCode) { case 0 : if(response.Preferences.Any()) { //Once a user is logged in, the application should output all the preferences //associated for that user to the screen. There is no maximum number of preferences //for a given user. Console.WriteLine("Showing Preferences..."); foreach (var preference in response.Preferences) { Console.WriteLine(preference.Name + " : " + preference.Setting); } } else { Console.WriteLine("User Has No Preferences..."); } break; case 1 : Console.WriteLine("Invalid user name and/or password..."); break; default : Console.WriteLine("Unknown error occurred..."); break; } }
public GetUserPreferencesResult GetUserPreferences(string userName, string password) { var result = new GetUserPreferencesResult(); if (DataAccessor.IsUserAuthenticated(userName, password)) { result.Preferences = DataAccessor.GetUserPreferences(userName); result.ReturnCode = 0; } else { //bad password or user name result.ReturnCode = 1; } return result; }