예제 #1
0
        // GET api/values?word=word
        public JObject Get(string word)
        {
            // service
            string    json   = "";
            WordModel result = lookupService.DbLookup(word);

            if (result == null)
            {
                result = lookupService.APILookup(word);
            }

            if (result != null)
            {
                json = JsonConvert.SerializeObject(result);
            }
            else
            {
                string error  = $"Merriam Webster API returned no results for \"{word}\". Is your input valid?";
                var    errObj = new { Error = error };
                json = JsonConvert.SerializeObject(errObj);
            }

            return(JObject.Parse(json));
            //return json;
        }
예제 #2
0
        /// <summary>
        /// Looks up the specified word. First checks the DB, then calls Dictionary API. If there are still no results an error message will be returned.
        /// </summary>
        /// <param name="word">The word to look up</param>
        /// <returns></returns>
        public ActionResult Search(string word) //word passed in to search for
        {
            //LookupService tries DB then Dictionary API
            var model = lookupService.DbLookup(word);

            if (model == null)
            {
                model = lookupService.APILookup(word);
            }

            if (model == null) //not found in DB nor Dictionary API
            {
                ViewBag.Title   = "Word Not Found";
                ViewBag.Message = $"Merriam Webster API returned no results for \"{word}\". Is your input valid?";
                return(View("Error"));
            }

            return(View("Index", model));
        }