public async Task <LikePostResponse> LikePostAsync(LikePostRequest request, string userId) { var entity = new PostLikeEntity { PostId = request.PostId, UserId = userId }; var result = await _postRepository.LikePostAsync(entity); if (!result) { return new LikePostResponse { StatusCode = (int)HttpStatusCode.Unauthorized } } ; var response = new LikePostResponse { StatusCode = (int)HttpStatusCode.Created }; return(response); }
public void Like(int postId, int userId) { if (_postLikeRepository.Table.Any(x => x.PostLikePostIdFk == postId && x.PostLikeUserIdFk == userId)) { throw new PostAlreadyLikedException(); } var like = new PostLikeEntity { PostLikePostIdFk = postId, PostLikeUserIdFk = userId, PostLikeCreatedAt = System.DateTime.Now }; _postLikeRepository.Insert(like); _postLikeRepository.SaveAll(); }
public async Task <bool> LikePostAsync(PostLikeEntity entity) { await _dbContext.PostLikes.AddAsync(entity); return(await SaveAsync()); }