Пример #1
0
        public async Task <Recipe> getRecipe(int recipeId)
        {
            try
            {
                Recipe returnRecipe = null;
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                var    builder = new UriBuilder(_configuration["recipeServiceEndpoint"] + "/api/recipes/" + recipeId);
                string url     = builder.ToString();
                var    result  = await client.GetAsync(url);

                switch (result.StatusCode)
                {
                case HttpStatusCode.OK:
                    returnRecipe        = JsonConvert.DeserializeObject <Recipe>(await client.GetStringAsync(url));
                    returnRecipe.phases = await _recipePhaseService.getPhasesFromRecipe(returnRecipe.recipeId);

                    return(returnRecipe);

                case HttpStatusCode.NotFound:
                    return(returnRecipe);

                case HttpStatusCode.InternalServerError:
                    return(returnRecipe);
                }
                return(returnRecipe);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                return(null);
            }
        }
Пример #2
0
 public async Task <IActionResult> Get(int recipeId)
 {
     return(Ok(await _recipePhaseService.getPhasesFromRecipe(recipeId)));
 }