public void Update(CommentPoint commentPoint) { _session.Clear(); _unitOfWork.BeginTransaction(_session); _unitOfWork.CommentPointRepository.Update(_session, commentPoint); _unitOfWork.Commit(); }
public (string message, long points) DownvoteComment(ApplicationUser user, int commentId) { _session.Clear(); var comment = _unitOfWork.CommentRepository.Get(_session, commentId); var commentPoint = _unitOfWork.CommentPointRepository.Get(_session, x => x.Comment.Id == commentId && x.ApplicationUser.Id == user.Id).FirstOrDefault(); if (commentPoint != null) { if (commentPoint.IsUpvoted) { try { _unitOfWork.BeginTransaction(_session); commentPoint.IsUpvoted = false; _unitOfWork.CommentPointRepository.Update(_session, commentPoint); _unitOfWork.Commit(); _session.Clear(); return(StringConstants.SUCCESS, _unitOfWork.CommentPointRepository.GetVotes(_session, commentId).overall); } catch (Exception ex) { return(ex.Message, _unitOfWork.CommentPointRepository.GetVotes(_session, commentId).overall); } } return(StringConstants.DUPLICATE, _unitOfWork.CommentPointRepository.GetVotes(_session, commentId).overall); } else { commentPoint = new CommentPoint { ApplicationUser = user, IsUpvoted = false, Comment = comment }; _unitOfWork.BeginTransaction(_session); _unitOfWork.CommentPointRepository.Create(_session, commentPoint); _unitOfWork.Commit(); _session.Clear(); return("Success", _unitOfWork.CommentPointRepository.GetVotes(_session, commentId).overall); } }