/* Steps: * Step One (when table objects are added): Convert into IngredientList objects * Step Two: Create a query with the items from the pantry and the allergy/diet restrictions * Step Three: Rank each recipe against the user preferences * Step Four: Return the sorted list */ public static async Task <List <Tuple <Recipe, double> > > GetRecommendations(IngredientList userPreferences, IngredientList pantry, IEnumerable <string> dietaryRestrictions, string diet) { if (client == null) { InitializeClient(); } //TODO: Set the RecipeSearchSettings with allergies and diets //Is there a way to figure out if the user settings have changed? String searchQuery = ""; foreach (String key in pantry.Keys) { if (pantry[key].Equals(1)) { searchQuery += key + " "; } } RecipeSearchSettings searchSettings = new RecipeSearchSettings(); if (dietaryRestrictions != null && dietaryRestrictions.Count() > 0) { foreach (var restriction in dietaryRestrictions) { var enumRestriction = Health.DEFAULT; Enum.TryParse <Health>(restriction, out enumRestriction); if (searchSettings.Health == null) { searchSettings.Health = new List <Health>(); } searchSettings.Health.Add(enumRestriction); } } if (diet != null) { var enumRestriction = Diet.BALANCED; Enum.TryParse <Diet>(diet, out enumRestriction); searchSettings.Diet = enumRestriction; } var recipeRecs = await client.SearchRecipes(searchQuery, searchSettings); if (recipeRecs.Count() == 0) { return(new List <Tuple <Recipe, double> >()); } else { return(GetTopTwelveRecipes(userPreferences, recipeRecs)); } }
public async Task <ActionResult> Index(string query) { var userClaims = User.Identity as System.Security.Claims.ClaimsIdentity; ViewBag.Name = userClaims?.FindFirst("name")?.Value; RecipeSearchSettings settings = new RecipeSearchSettings() { Time = 50, Diet = Diet.LOW_CARB, Excluded = new List <string> { "tofu" }, }; var result = await edamamClient.SearchRecipes(query, settings); return(View(result)); }