public async Task <ActionResult <List <PostAndKeyword> > > GetWriterPost([FromBody] UsernameDTO usernameDTO) { List <TblPosts> listNotHaving = getListPostNotInHavingPosts(usernameDTO.Username); List <TblPosts> listResponse = new List <TblPosts>(); List <PostAndKeyword> listPostAndKeywordResponse = new List <PostAndKeyword>(); for (int i = 0; i < listNotHaving.Count; i++) { TblPosts currentPost = listNotHaving[i]; if (currentPost.PostType.Equals("Writer")) { listResponse.Add(currentPost); PostAndKeyword postAndKeyword = new PostAndKeyword(); postAndKeyword.Id = currentPost.Id; postAndKeyword.Title = currentPost.Title; postAndKeyword.Description = currentPost.Description; postAndKeyword.CharacterLimit = currentPost.CharacterLimit; postAndKeyword.Amount = currentPost.Amount; postAndKeyword.PostType = currentPost.PostType; postAndKeyword.RelatedDocument = currentPost.RelatedDocument; postAndKeyword.IsPublic = currentPost.IsPublic; postAndKeyword.CreatedDate = currentPost.CreatedDate; postAndKeyword.Status = currentPost.Status; postAndKeyword.listKeywords = findListKeyByPostId(currentPost.Id); listPostAndKeywordResponse.Add(postAndKeyword); } } return(listPostAndKeywordResponse); }
public async Task <ActionResult <List <PostAndKeyword> > > GetAcceptedPosts(UsernameDTO usernameDTO) { List <TblUsersHavingPosts> listRequested = _context.TblUsersHavingPosts .FromSqlRaw("select * from tblUsersHavingPosts where Username = {0} and Status = 'requested'", usernameDTO.Username) .ToList <TblUsersHavingPosts>(); List <TblPosts> listAccepted = _context.TblPosts .FromSqlRaw("select * from tblPosts where Id in " + "(select PostId from tblUsersHavingPosts where Username = {0} and Status = 'accepted')", usernameDTO.Username) .ToList <TblPosts>(); List <TblPosts> listResponse = new List <TblPosts>(); List <PostAndKeyword> listPostAndKeywordResponse = new List <PostAndKeyword>(); if (listAccepted.Count > 0) { for (int i = 0; i < listAccepted.Count; i++) { TblPosts currentPost = listAccepted[i]; if (currentPost.PostType.Equals("Writer") || currentPost.PostType.Equals("Design") || currentPost.PostType.Equals("Translate")) { listResponse.Add(currentPost); PostAndKeyword postAndKeyword = new PostAndKeyword(); postAndKeyword.Id = currentPost.Id; postAndKeyword.Title = currentPost.Title; postAndKeyword.Description = currentPost.Description; postAndKeyword.CharacterLimit = currentPost.CharacterLimit; postAndKeyword.Amount = currentPost.Amount; postAndKeyword.PostType = currentPost.PostType; postAndKeyword.RelatedDocument = currentPost.RelatedDocument; postAndKeyword.IsPublic = currentPost.IsPublic; postAndKeyword.CreatedDate = currentPost.CreatedDate; postAndKeyword.Status = currentPost.Status; postAndKeyword.listKeywords = findListKeyByPostId(currentPost.Id); listPostAndKeywordResponse.Add(postAndKeyword); } } _context.TblUsersHavingPosts.RemoveRange(listRequested); await _context.SaveChangesAsync(); return(listPostAndKeywordResponse); } return(null); }