Ejemplo n.º 1
0
        public IActionResult LikeReview([FromBody] ReviewIdParameter model)
        {
            ReviewLikeResult ret           = new ReviewLikeResult();
            Claim            idClaim       = User.FindFirst("sub");
            Claim            usernameClaim = User.FindFirst("nickname");

            if (idClaim == null)
            {
                return(Unauthorized());
            }
            ret = _reviewActionService.LikeReview(idClaim.Value, model.ReviewId);
            if (ret.IsActionSucceed && ret.PostId != 0)
            {
                _bus.Publish <UserLikedReviewAction>(new UserLikedReviewAction()
                {
                    UserId         = idClaim.Value,
                    ReviewAuthorId = ret.ReviewAuthorId,
                    ReviewId       = model.ReviewId,
                    PostId         = ret.PostId,
                    Username       = usernameClaim.Value,
                    DateUtcAction  = DateTime.UtcNow
                }, "#");
            }
            return(Ok(Json(ret)));
        }
Ejemplo n.º 2
0
        public ReviewLikeResult LikeReview(string currUserId, int reviewId = -1)
        {
            GetUserLikes(currUserId);
            ReviewLikeResult ret = new ReviewLikeResult
            {
                IsActionSucceed = true
            };

            ret.SuccessInformation.SuccessType = SuccessType.NoAction;
            if (reviewId == -1 || string.IsNullOrEmpty(currUserId))
            {
                ret.IsActionSucceed = false;
                ret.SuccessInformation.SuccessType = SuccessType.NoAction;
                return(ret);
            }
            UserReview rlike = _dbEntitySet.FirstOrDefault(p => p.ReviewId == reviewId && p.UserInfoId == currUserId);
            var        rev   = _reviewSet.Select(p => new { p.Id, p.UserId, p.PostId }).FirstOrDefault(p => p.Id == reviewId);

            ret.ReviewAuthorId = rev.UserId;
            ret.PostId         = rev.PostId ?? 0;
            if (rlike == null)
            {
                _dbEntitySet.Add(new UserReview()
                {
                    LikeStatus = LikeStatus.Like,
                    ReviewId   = reviewId,
                    UserInfoId = currUserId
                });
                ret.LikeStatus = LikeStatus.Like;
            }
            else if (rlike.LikeStatus == LikeStatus.Dislike || rlike.LikeStatus == LikeStatus.None)
            {
                rlike.LikeStatus = LikeStatus.Like;
                ret.LikeStatus   = LikeStatus.Like;
                _context.SetChildAsModified(rlike);
            }
            else
            {
                ret.IsActionSucceed = false;
                return(ret);
            }
            if (_context.SaveChanges() != 0)
            {
                prevDislikedReviews = prevDislikedReviews.Where(val => val != reviewId).ToArray();
                prevLikedReviews    = prevLikedReviews.Append(reviewId).Distinct().ToArray();

                _userLikeCacheService.SetUserLikedReviewsIds(currUserId, prevLikedReviews, 10);
                _userLikeCacheService.SetUserDisikedReviewsIds(currUserId, prevDislikedReviews, 10);
            }
            ;
            return(ret);
        }
Ejemplo n.º 3
0
        public IActionResult UndislikeReview([FromBody] ReviewIdParameter model)
        {
            ReviewLikeResult ret = new ReviewLikeResult();
            var   user           = HttpContext.User;
            Claim idClaim        = User.FindFirst("sub");

            if (idClaim == null)
            {
                return(Unauthorized());
            }
            ret = _reviewActionService.UndislikeReview(idClaim.Value, model.ReviewId);
            if (ret.IsActionSucceed)
            {
                _bus.Publish <UserUndislikedReviewAction>(new UserUndislikedReviewAction()
                {
                    UserId        = idClaim.Value,
                    ReviewId      = model.ReviewId,
                    DateUtcAction = DateTime.UtcNow
                }, "#");
            }
            return(Ok(Json(ret)));
        }
Ejemplo n.º 4
0
        public ReviewLikeResult UndislikeReview(string currUserId, int reviewId = -1)
        {
            GetUserLikes(currUserId);
            ReviewLikeResult ret = new ReviewLikeResult
            {
                IsActionSucceed = true
            };

            ret.SuccessInformation.SuccessType = DataExtensions.Models.SuccessType.NoAction;
            if (reviewId == -1 || string.IsNullOrEmpty(currUserId))
            {
                ret.IsActionSucceed            = false;
                ret.ErrorInformation.ErrorType = DataExtensions.Models.ErrorType.NoAction;
                return(ret);
            }
            UserReview rlike = _dbEntitySet.FirstOrDefault(p => p.ReviewId == reviewId && p.UserInfoId == currUserId && p.LikeStatus == LikeStatus.Dislike);

            if (rlike == null)
            {
                ret.IsActionSucceed = false;
                return(ret);
            }
            else
            {
                rlike.LikeStatus = LikeStatus.None;
                ret.LikeStatus   = LikeStatus.None;
                _context.SetChildAsDeleted(rlike);
            }
            if (_context.SaveChanges() != 0)
            {
                prevDislikedReviews = prevDislikedReviews.Where(val => val != reviewId).ToArray();

                _userLikeCacheService.SetUserDisikedReviewsIds(currUserId, prevDislikedReviews, 10);
            }
            ;
            return(ret);
        }