public async Task <ArticleCommentsDto> AddComment(ArticleCommentsDto commentDto) { var article = await _context.Articles.FindAsync(commentDto.ArticleId); if (article == null) { return(null); } var comment = _mapper.Map <ArticleComment>(commentDto); _context.ArticleComments.Add(comment); await _context.SaveChangesAsync(); return(_mapper.Map <ArticleCommentsDto>(comment)); }
public async Task <IActionResult> AddComment(int id, ArticleCommentsDto comment) { comment.ArticleId = id; comment.AddedDate = DateTime.Now; var result = await _repo.AddComment(comment); if (result == null) { return(StatusCode(StatusCodes.Status500InternalServerError, new Response <ArticleCommentsDto>() { Succeeded = false, Message = "مقاله پیدا نشد" })); } return(Ok(new Response <ArticleCommentsDto>(result) { Message = "کامنت با موفقین اضافه شد" })); }