Exemplo n.º 1
0
        public IActionResult SearchOxford([Bind] Word word)
        {
            var wordRetrieval = new OnlineWordRetrieval();

            wordRetrieval.GetWordOxford(word.Name);

            var newWord = new Word
            {
                Name         = "boat",
                PartOfSpeech = "noun",
                Definition   = "A small vessel propelled on water by oars, sails, or an engine.",
                Example      = "A fishing boat drifted in the lake.",
                Synonyms     = "vessel, craft, watercraft, ship ",
                List         = "1st - 2018 - words 18-34 ",
                Grade        = 1
            };

            return(RedirectToAction("Create", newWord));
        }
Exemplo n.º 2
0
        public IActionResult Search([Bind] Word word)
        {
            var wordRetrieval = new OnlineWordRetrieval();
            var words         = wordRetrieval.GetWordGoogle(word.Name).ToList();
            var newWord       = new Word();

            // words[0], words[1], etc. are the words
            // words[0].Word == name of the word
            // words[0].Meaning dictionary of meanings
            var firstWord = words.First();

            newWord.Name  = firstWord.Word;
            newWord.List  = word.List;
            newWord.Grade = word.Grade;

            var partOfSpeech = firstWord.Meaning.First();

            newWord.PartOfSpeech = partOfSpeech.Key;

            var definition = partOfSpeech.Value.First(); // Get first definition/example, then capitalize first letters and check they end with period.

            newWord.Definition = definition.Definition.First().ToString().ToUpper() + definition.Definition.Substring(1);
            newWord.Definition = newWord.Definition.EndsWith(".") ? newWord.Definition : newWord.Definition + ".";

            if (definition.Example != null)
            {
                newWord.Example = definition.Example.First().ToString().ToUpper() + definition.Example.Substring(1);
                newWord.Example = newWord.Example.EndsWith(".") ? newWord.Example : newWord.Example + ".";
            }

            if (definition.Synonyms != null)
            {
                newWord.Synonyms = String.Join(", ", definition.Synonyms.Take(7));
            }

            return(RedirectToAction("Create", newWord));
        }