public IList<Food> SearchForFood(SearchService SearchService, IList<Food> searchResults, String Key, String Exp, String Value) { int numericValue; double dNumericValue; if (searchResults == null) { throw new ArgumentException("Error during search please try again"); } if (Key == "" || Value == "" || Exp == "") { return searchResults; } Key = Key.ToLower(); switch (Key.Trim()) { case "name": return SearchService.ApplySearchContains<Food>(searchResults, "Name", Exp, Value, true); case "desc": case "description": return SearchService.ApplySearchContains<Food>(searchResults, "Description", Exp, Value, true); case "category": case "cat": FoodCategory cat = FoodTracker.GetAllFoodCategories(true).Where(x => x.Name.ToLower() == Value).FirstOrDefault(); return SearchService.ApplySearchEquals<Food>(searchResults, "Category", Exp, cat); case "cal": case "calories": if (!Int32.TryParse(Value, out numericValue)) { throw new ArgumentException("Calories has to be a number in order to search"); } else { return SearchService.ApplySearchNumerical<Food>(searchResults, "Calories", Exp, numericValue); } case "sugar": case "sugars": if (!Double.TryParse(Value, out dNumericValue)) { throw new ArgumentException("Sugar has to be a number in order to search"); } else { return SearchService.ApplySearchNumerical<Food>(searchResults, "Sugars", Exp, dNumericValue); } case "fat": case "fats": if (!double.TryParse(Value, out dNumericValue)) { throw new ArgumentException("Fat has to be a number in order to search"); } else { return SearchService.ApplySearchNumerical<Food>(searchResults, "Fat", Exp, dNumericValue); } case "satfat": case "satfats": case "saturates": if (!double.TryParse(Value, out dNumericValue)) { throw new ArgumentException("Saturates has to be a number in order to search"); } else { return SearchService.ApplySearchNumerical<Food>(searchResults, "Saturates", Exp, dNumericValue); } case "salt": if (!double.TryParse(Value, out dNumericValue)) { throw new ArgumentException("Salt has to be a number in order to search"); } else { return SearchService.ApplySearchNumerical<Food>(searchResults, "Salt", Exp, dNumericValue); } default: throw new ArgumentException(Key.Trim() + "is not a valid search key"); } }