示例#1
0
        public async Task <IActionResult> PutTblKeywords(int id, TblKeywords tblKeywords)
        {
            if (id != tblKeywords.Id)
            {
                return(BadRequest());
            }

            _context.Entry(tblKeywords).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TblKeywordsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
示例#2
0
        public async Task <ActionResult <TblKeywords> > PostTblKeywords(TblKeywords tblKeywords)
        {
            _context.TblKeywords.Add(tblKeywords);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (TblKeywordsExists(tblKeywords.Id))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetTblKeywords", new { id = tblKeywords.Id }, tblKeywords));
        }
        //Nhận vào PostID và trả về 1 list các bài Keyword theo PostID
        private List <string> findListKeyByPostId(int id)
        {
            List <TblPostsHavingKeywords> listHavingKeyword = _context.TblPostsHavingKeywords.ToList <TblPostsHavingKeywords>();
            List <TblKeywords>            listTblKeywords   = _context.TblKeywords.ToList <TblKeywords>();

            List <int?>   listKeywordID       = new List <int?>();
            List <string> listKeywordResponse = new List <string>();

            // Lấy ra 1 list KeywordID
            for (int i = 0; i < listHavingKeyword.Count; i++)
            {
                TblPostsHavingKeywords current = listHavingKeyword[i];

                if (id == current.PostId)
                {
                    listKeywordID.Add(current.KeywordId);
                }
            }

            // Chạy vòng for để tìm ra List Keyword
            if (listKeywordID != null)
            {
                for (int i = 0; i < listKeywordID.Count; i++)
                {
                    int?currentListID = listKeywordID[i];

                    for (int j = 0; j < listTblKeywords.Count; j++)
                    {
                        TblKeywords currentTblKeyword = listTblKeywords[j];
                        if (currentTblKeyword.Id == currentListID)
                        {
                            listKeywordResponse.Add(currentTblKeyword.Name);
                        }
                    }
                }
            }

            return(listKeywordResponse);
        }