public Recipe[] RecommendRecipes(string id) { RecipeClient recipeClient = new RecipeClient(); var recipes = recipeClient.RecommendRecipes(id); return(recipes); }
public Recipe GetMealPlan(string timeFrame, int targetCalories, string diet, string exclude) { RecipeClient recipeClient = new RecipeClient(); var recipe = recipeClient.GetMealPlan(timeFrame, targetCalories, diet, exclude); return(recipe); }
public Recipe[] SearchRecipeByIngredients(int numberOfRecipesReturned, string ingredients) { RecipeClient recipeClient = new RecipeClient(); var recipes = recipeClient.SearchRecipeByIngredients(numberOfRecipesReturned, ingredients); return(recipes); }
public Recipe SearchRecipe(string diet, string excludeIngredients, string intolerances, int numberOfRecipes, string type, string query) { RecipeClient recipeClient = new RecipeClient(); var recipe = recipeClient.SearchRecipe(diet, excludeIngredients, intolerances, numberOfRecipes, type, query); return(recipe); }
static object Search(SearchOptions options) { RecipeClient client = SearchClientFactory.CreateClient(options); // Denna övning använder ElasticSearch // https://www.elastic.co/ // Dokumentation över hur man ställer frågor // https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/writing-queries.html // 1. Hitta 20 recept som innehåller ordet "fisk". // 2. Sortera sökträffarna efter rating. // 3. Räkna alla recept som är upplagda av Per Morberg. // 4. Hitta 30 recept som tillhör kategorin Bönor. // 5. Räkna alla recept som har en tillagningstid på under 10 minuter (tips: TimeSpan lagras som ticks i index). //var result = client.Search(s => s.QueryOnQueryString(options.Query) //.Sort(order => order.Descending(field => field)) //.Take(20)); //var result = client.Count(Search => Search.Query( // query => query.Match( // match => match.Field(field => field.Author).Query("Per Moberg")))); var result = client.Search(serrch => serrch.QueryOnQueryString("categories: \"bönor\"")); return(0); }
public void GetRecipesTestFails() { Mock <IApiClient> mock = new Mock <IApiClient>(); IRecipeClient client = new RecipeClient(mock.Object); Task <RecipeResponse> response = client.GetRecipe(""); var actual = response.Status; var expected = TaskStatus.Faulted; Assert.AreEqual(expected, actual); }
static object Search(SearchOptions options) { RecipeClient client = SearchClientFactory.CreateClient(options); // Denna övning använder ElasticSearch // https://www.elastic.co/ // Dokumentation över hur man ställer frågor // https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/writing-queries.html // 1. Hitta 20 recept som innehåller ordet "fisk". // 2. Sortera sökträffarna efter rating. // 3. Räkna alla recept som är upplagda av Per Morberg. // 4. Hitta 30 recept som tillhör kategorin Bönor. // 5. Räkna alla recept som har en tillagningstid på under 10 minuter (tips: TimeSpan lagras som ticks i index). return(0); }
static object Index(IndexOptions options) { RecipeDocument recipe; try { recipe = RecipeFactory.CreateFrom(options.Url); } catch (Exception ex) { Console.WriteLine(ex.Message); return(1); } RecipeClient client = SearchClientFactory.CreateClient(options); var response = client.Index(recipe); Console.WriteLine($"Index: {FormatApiCall(response.ApiCall)}"); return(0); }
public void GetRecipeTest() { Mock <IApiClient> mock = new Mock <IApiClient>(); HttpResponseMessage responseMessage = new HttpResponseMessage(System.Net.HttpStatusCode.OK) { Content = new StringContent("{ 'recipe': { 'publisher': 'Jamie Oliver', 'f2f_url': 'http://food2fork.com/view/bc8acd', 'ingredients': ['12 Jacob's cream crackers', '8 sprigs of fresh flat-leaf parsley', '500 g quality minced beef', '2 heaped tablespoons Dijon mustard, optional'], 'source_url': 'http://www.jamieoliver.com/recipes/beef-recipes/a-cracking-burger', 'recipe_id': 'bc8acd', 'image_url': 'http://static.food2fork.com/7_1_1350663561_lrgf1c4.jpg', 'social_rank': 99.99999543148996, 'publisher_url': 'http://www.jamieoliver.com', 'title': 'A cracking burger'}}") }; mock.SetReturnsDefault <Task <HttpResponseMessage> >(Task.FromResult(responseMessage)); IRecipeClient client = new RecipeClient(mock.Object); mock.Setup(x => x.GetFormEncodedContent("", new KeyValuePair <string, string>[] { new KeyValuePair <string, string>("", "") })) .Returns(Task.FromResult(responseMessage)); Task <RecipeResponse> response = client.GetRecipe("bc8acd"); var actual = response.Status; var expected = TaskStatus.WaitingForActivation; Assert.AreEqual(expected, actual); }
public Recipe GetRecipeById(string id) { RecipeClient recipeClient = new RecipeClient(); var recipe = recipeClient.GetRecipeById(id); Recipe newRecipe = new Recipe(); newRecipe.Title = recipe.Title; newRecipe.IsVegan = recipe.IsVegan; newRecipe.Image = recipe.Image; newRecipe.IsVegetarian = recipe.IsVegetarian; newRecipe.Instructions = recipe.Instructions; newRecipe.MarkedAsFavorite = recipe.MarkedAsFavorite; newRecipe.Url = recipe.Url; newRecipe.Comment = recipe.Comment; newRecipe.Servings = recipe.Servings; //newRecipe = recipe; //var userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier); //var client = _context.Clients.Where(c => c.ApplicationUserId == userId).FirstOrDefault(); //newRecipe.ClientId = client.Id; _context.Recipes.Add(newRecipe); _context.SaveChangesAsync(); // //return RedirectToAction("Index", "Recipes"); return(recipe); }
public HomeController(ILogger <HomeController> logger, RecipeClient recipeClient, RecipeContext recipeDbContext) { _logger = logger; _recipeClient = recipeClient; _recipeDbContext = recipeDbContext; }
public RecipeController(RecipesDBContext recipesDbContext, UserManager <IdentityUser> userManager, RecipeClient RecipeClient) { _recipesDbContext = recipesDbContext; _userManager = userManager; _RecipeClient = RecipeClient; }