public async Task <IActionResult> DeleteCommentLike([FromBody] CreateCommentLikeDto createCommentLikeDto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var commentLike = await context.CommentLikes.SingleOrDefaultAsync(like => like.CommentId == createCommentLikeDto.CommentId && like.UserId == createCommentLikeDto.UserId); if (commentLike == null) { return(NotFound()); } context.CommentLikes.Remove(commentLike); await context.SaveChangesAsync(); var commentLikeDto = new CommentLikeDto { CommentId = commentLike.CommentId, CountLike = await context.CommentLikes .Where(like => like.CommentId == commentLike.CommentId).CountAsync() }; return(Ok(commentLikeDto)); }
public async Task <IActionResult> PostCommentLike([FromBody] CreateCommentLikeDto createCommentLikeDto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var newCommentLike = mapper.Map <CreateCommentLikeDto, CommentLike>(createCommentLikeDto); context.CommentLikes.Add(newCommentLike); await context.SaveChangesAsync(); var commentLikeDto = new CommentLikeDto { CommentId = newCommentLike.CommentId, CountLike = await context.CommentLikes .Where(like => like.CommentId == newCommentLike.CommentId).CountAsync() }; return(CreatedAtRoute(new { id = newCommentLike.Id }, commentLikeDto)); }