/// <summary>
        /// Get word data from api and create word obj for each meaning
        /// </summary>
        /// <param name="wordText"></param>
        /// <returns></returns>
        public async Task <List <Word> > GetWord(string wordText)
        {
            string wordJson = await GetWordFromApi(wordText);

            _logger.LogDebug("Json form Words API: \n " + wordJson);
            ApiWord     apiWord      = JsonConvert.DeserializeObject <ApiWord>(wordJson);
            List <Word> wordsInQuery = new List <Word>();

            _logger.LogDebug(apiWord.ToString());
            foreach (Results res in apiWord.Results)
            {
                if (wordsInQuery.Count >= 4)
                {
                    break;
                }
                if (res.Examples == null)
                {
                    continue;
                }

                Word word = new Word();
                word.WordText = apiWord.Word;
                word.Meaning  = res.Definition;
                word.Example  = res.Examples.FirstOrDefault();
                wordsInQuery.Add(word);
            }


            return(wordsInQuery);
        }
예제 #2
0
        /// <summary>
        /// 发布接口 页面
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public ActionResult ApiAdd(int apiId = 0, int type = 1, int act = 0)
        {
            ApiWord apiWord = ncBase.CurrentEntities.ApiWord.Where(n => n.ApiWordId == apiId).FirstOrDefault();

            ViewBag.Act = act;
            return(View(apiWord));
        }
예제 #3
0
        public JsonResult ApiNew(ApiWord entity)
        {
            entity.Publisher = this.GetLoginUser().Name;

            ApiWord apiWord = new ApiWord();

            if (entity.ApiWordId > 0)
            {
                apiWord = ncBase.CurrentEntities.ApiWord.Where(n => n.ApiWordId == entity.ApiWordId).FirstOrDefault();
                if (apiWord.IsNoNull())//修改
                {
                    apiWord.Type           = entity.Type;
                    apiWord.Title          = entity.Title;
                    apiWord.ApiWordContent = entity.ApiWordContent;
                    apiWord.Publisher      = entity.Publisher;
                    apiWord.Url            = entity.Url;
                    apiWord.Method         = entity.Method;
                    apiWord.IsLogin        = entity.IsLogin;
                    ncBase.CurrentEntities.SaveChanges();
                    return(Json(new { status = apiWord.ApiWordId }));
                }
            }
            apiWord                = new ApiWord();
            apiWord.Type           = entity.Type;
            apiWord.Title          = entity.Title;
            apiWord.ApiWordContent = entity.ApiWordContent;
            apiWord.Publisher      = entity.Publisher;
            apiWord.Url            = entity.Url;
            apiWord.Method         = entity.Method;
            apiWord.CreateTime     = DateTime.Now;
            apiWord.Hits           = 0;
            apiWord.IsLogin        = entity.IsLogin;
            ncBase.CurrentEntities.AddToApiWord(apiWord);
            ncBase.CurrentEntities.SaveChanges();

            return(Json(new { status = apiWord.ApiWordId }));
        }