Esempio n. 1
0
        public IActionResult GenerateAllergenTag([FromBody] List <RecipeIngredient> recipeIngredients)
        {
            GenerateTag trial = new GenerateTag(_recipesService, _context);

            string allergens = trial.GetAllergenTag(recipeIngredients);

            List <RecipeTag> tags = new List <RecipeTag>();

            tempAllergenTags tempAlTags = JsonConvert.DeserializeObject <tempAllergenTags>(allergens);

            if (tempAlTags.allergens != null)
            {
/*                Debug.WriteLine(tempAlTags.allergens[0]);
 */
                for (int i = 0; i < tempAlTags.allergens.Count; i++)
                {
                    tags.Add(new RecipeTag
                    {
                        IsAllergenTag = true,
                        Tag           = new Tag
                        {
                            TagName = tempAlTags.allergens[i],
                            Warning = tempAlTags.allergens[i]
                        }
                    });
                }
            }

            string json = JsonConvert.SerializeObject(tags, Formatting.Indented);

            return(Json(new { tags = json }));
        }
Esempio n. 2
0
        public async Task <ActionResult <List <RecipeTag> > > GenerateAllergenTags([FromBody] List <RecipeIngredient> recipeIngredients)
        {
            Debug.Write("Reached generate A Tags");

            GenerateTag trial = new GenerateTag(_recipesService);

            string allergens = trial.GetAllergenTag(recipeIngredients);

            List <RecipeTag> tags = new List <RecipeTag>();

            tempAllergenTags tempAlTags = JsonConvert.DeserializeObject <tempAllergenTags>(allergens);

            if (tempAlTags.allergens != null)
            {
                Debug.WriteLine(tempAlTags.allergens[0]);
                for (int i = 0; i < tempAlTags.allergens.Count; i++)
                {
                    tags.Add(new RecipeTag
                    {
                        IsAllergenTag = true,
                        Tag           = new Tag
                        {
                            TagName = tempAlTags.allergens[i],
                            Warning = tempAlTags.allergens[i]
                        }
                    });
                }
            }

            return(tags);
        }
Esempio n. 3
0
        public string Get(int id)
        {
            string uirWebAPI   = "http://localhost:5000/api/allergentags";
            string webResponse = string.Empty;

            Debug.WriteLine(id);

            List <RecipeIngredient> recipeIngredients = _recipesService.FindRecipeStepsByRecipeId(id);

            Debug.WriteLine(recipeIngredients[0]);

            List <string> ingredients = new List <string>();

            foreach (RecipeIngredient ri in recipeIngredients)
            {
                ingredients.Add(ri.Ingredient);
            }

            recipeIngredientsJson toSend = new recipeIngredientsJson();

            toSend.ingredients = ingredients;

            try
            {
                Uri        uri            = new Uri(uirWebAPI);
                WebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(uri);
                httpWebRequest.ContentType = "application/json";
                httpWebRequest.Method      = "POST";
                using (StreamWriter streamWriter =
                           new StreamWriter(httpWebRequest.GetRequestStream()))
                {
                    streamWriter.Write(JsonConvert.SerializeObject(toSend));
                }
                HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                using (StreamReader streamReader = new StreamReader(httpWebResponse.GetResponseStream()))
                {
                    webResponse = streamReader.ReadToEnd();
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
            }
            Debug.WriteLine(webResponse);

            tempAllergenTags tempAlTags = JsonConvert.DeserializeObject <tempAllergenTags>(webResponse);

            if (tempAlTags.allergens != null)
            {
                Debug.WriteLine(tempAlTags.allergens[0]);
            }

            return(webResponse);
        }
Esempio n. 4
0
        public string GetAllergenTag(List <RecipeIngredient> recipeIngredients)
        {
            string uirWebAPI = "http://recipe4menlp-env.eba-zsgvuj5a.ap-southeast-1.elasticbeanstalk.com/api/allergentags";


            /*            string uirWebAPI = "http://127.0.0.1:5000/api/allergentags";
             */
            string webResponse = string.Empty;


            Debug.WriteLine(recipeIngredients[0]);

            List <string> ingredients = new List <string>();

            foreach (RecipeIngredient ri in recipeIngredients)
            {
                ingredients.Add(ri.Ingredient);
            }

            recipeIngredientsJson toSend = new recipeIngredientsJson();

            toSend.ingredients = ingredients;

            List <Tag>    allTags           = _context.Tags.ToList();
            List <string> corpus_allergen   = new List <string>();
            List <string> corpus_ingredient = new List <string>();

            foreach (Tag tag in allTags)
            {
                corpus_allergen.Add(tag.Warning);
                corpus_ingredient.Add(tag.TagName);
            }
            toSend.corpus_allergen   = corpus_allergen;
            toSend.corpus_ingredient = corpus_ingredient;

            try
            {
                Uri        uri            = new Uri(uirWebAPI);
                WebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(uri);
                httpWebRequest.ContentType = "application/json";
                httpWebRequest.Method      = "POST";
                using (StreamWriter streamWriter =
                           new StreamWriter(httpWebRequest.GetRequestStream()))
                {
                    streamWriter.Write(JsonConvert.SerializeObject(toSend));
                }
                HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                using (StreamReader streamReader = new StreamReader(httpWebResponse.GetResponseStream()))
                {
                    webResponse = streamReader.ReadToEnd();
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
            }
            Debug.WriteLine(webResponse);

            tempAllergenTags tempAlTags = JsonConvert.DeserializeObject <tempAllergenTags>(webResponse);

/*            if (tempAlTags.allergens != null)
 *          {
 *              Debug.WriteLine(tempAlTags.allergens[0]);
 *          }*/

            return(webResponse);
        }