Example #1
0
        public async Task <IEnumerable <RecipeApiModel> > Search(SearchRecipeParameters parameters)
        {
            var all = await recipeAdapter.GetAllRecipes();

            BaseFilter <RecipeApiModel> filter = new NameFilter <RecipeApiModel>(parameters.Name);

            if (parameters.Type != ERecipeType.None)
            {
                filter = new RecipeTypeFilter(parameters.Type, filter);
            }

            return(filter.Filter(all));
        }
Example #2
0
        public async Task <List <RecipeModel> > Search(SearchRecipeParameters parameters)
        {
            try
            {
                var json = JsonConvert.SerializeObject(parameters);

                var data = new StringContent(json, Encoding.UTF8, "application/json");

                var client = new HttpClient();

                var response = await client.PostAsync(new Uri("http://localhost:5005/api/recipe/search"), data);

                string result = response.Content.ReadAsStringAsync().Result;

                var jsonReslt = JsonConvert.DeserializeObject <List <RecipeModel> >(result);
                client.Dispose();
                return(jsonReslt);
            }
            catch (Exception)
            {
                return(new List <RecipeModel>());
            }
        }
Example #3
0
        public async Task <IActionResult> Search([FromBody] SearchRecipeParameters parameters)
        {
            var result = await recipeService.Search(parameters);

            return(Ok(result));
        }