Esempio n. 1
0
        public void UpVote(ClaimsPrincipal user, int postId)
        {
            var userId     = _userService.GetUserWithRoles(user).User.Id;
            var postRating = _postRatingRepository.Get(x => x.UserId == userId && x.PostId == postId);

            if (postRating != null)
            {
                if (postRating.IsLiked)
                {
                    _postRatingRepository.Remove(postRating);
                }
                else
                {
                    postRating.IsLiked    = true;
                    postRating.UpdateDate = DateTime.Now;
                }
            }
            else
            {
                postRating = new PostRating()
                {
                    PostId     = postId,
                    CreateDate = DateTime.Now,
                    IsLiked    = true,
                    UserId     = userId
                };

                _postRatingRepository.Add(postRating);
            }

            _postRatingRepository.Save();
        }
        public bool IsAddedRating(string userId, int postId, int mark)
        {
            var userIsVoted = postRatingRepository.UserIsVoted(userId, postId);

            if (userIsVoted)
            {
                return(false);
            }
            else
            {
                postRatingRepository.AddRating(new PostRating {
                    UserId = userId, PostId = postId, Mark = mark
                });

                postRatingRepository.Save();

                return(true);
            }
        }