static internal string GetRestaurants(params string[] restaurantParams) { List <Restaurant> restaurants = new List <Restaurant>(); List <RestaurantInfo> restaurantsInfo = new List <RestaurantInfo>(); string response = null; // 1) Validate input ValidateInput.Validate(restaurantParams); // 2) Dependency injection for entity storage Storage storage = new Storage(new DBUtility()); // 3) Get list of restaurants from database restaurants = storage.GetRestaurantModels(); // 4) Convert list of restaurant models to list of restaurant output objects restaurantsInfo = ConvertModels.GetRestaurantInfos(restaurants); // 5) Sort list based on optional parameters if (restaurantParams.Length > 1) { SortRestaurants.Sort(ref restaurantsInfo, restaurantParams); } // 6) Create response json string response = JsonConvert.SerializeObject(restaurantsInfo); // 7) Return response to client return(response); }
static public List <RestaurantInfo> GetRestaurants(params string[] restaurantParams) { List <Restaurant> restaurants = new List <Restaurant>(); List <RestaurantInfo> restaurantsInfo = new List <RestaurantInfo>(); try { // 1) Validate input ValidateInput.Validate(restaurantParams); // 2) Dependency injection for entity storage Storage storage = new Storage(new DBUtility()); // 3) Get list of restaurants from database restaurants = storage.GetRestaurantModels(); // 4) Convert list of restaurant models to list of restaurant output objects restaurantsInfo = ConvertModels.GetRestaurantInfos(restaurants); // 5) Sort list based on optional parameters if (restaurantParams.Length > 1) { SortRestaurants.Sort(ref restaurantsInfo, restaurantParams); } // 6) Create response json string // response = JsonConvert.SerializeObject(restaurantsInfo); } catch (InvalidParameterException e) { logger.Error(e.Message); } catch (InvalidCommandException e) { logger.Error(e.Message); } catch (InvalidInputException e) { logger.Error(e.Message); } catch (DbException e) { logger.Error(e.Message); } catch (Exception e) { logger.Error(e.Message); } // 7) Return response to client return(restaurantsInfo); }