public async Task DeleteReactionPost(int postId, Guid currentUserId) { ReactionPost reactionPost = new ReactionPost { PostId = postId, UserId = currentUserId }; _context.ReactionPost.Remove(reactionPost); await _context.SaveChangesAsync(); }
public async Task <ReactionPost> AddReactionPost(ReactionPost reactionPost, Guid authorUser) { if (await _context.ReactionPost.AnyAsync(x => x.PostId == reactionPost.PostId && x.UserId == authorUser)) { throw ExceptionFactory.SoftException(ExceptionEnum.ReactionAlreadyExist, $"another reaction already exist"); } if (!await _context.ReactionTypePost.AnyAsync(x => x.ReactionId == reactionPost.ReactionId)) { throw ExceptionFactory.SoftException(ExceptionEnum.ReactionDoesNotExist, $"reaction does not exist"); } reactionPost.UserId = authorUser; var insertedReactionPost = await _context.ReactionPost.AddAsync(reactionPost); await _context.SaveChangesAsync(); return(insertedReactionPost.Entity); }