Пример #1
0
        public bool IsLikeContent(Guid contentId, Guid userId)
        {
            ContentLike contentLike = UnitOfWork.ContentLikeRepository
                                      .Get(current => current.UserId == userId && current.ContentId == contentId).FirstOrDefault();

            if (contentLike == null)
            {
                return(false);
            }

            return(contentLike.IsLike);
        }
Пример #2
0
        public bool LikeAndDislike(PostLikeInputViewModel likeInputViewModel, Guid userId)
        {
            Guid    contentId = new Guid(likeInputViewModel.ContentId);
            Content content   = UnitOfWork.ContentRepository.GetById(contentId);

            if (content == null)
            {
                return(false);
            }

            ContentLike contentLike = UnitOfWork.ContentLikeRepository
                                      .Get(current => current.ContentId == contentId && current.UserId == userId).FirstOrDefault();

            if (contentLike != null)
            {
                if (contentLike.IsLike != likeInputViewModel.IsLike)
                {
                    contentLike.IsLike = likeInputViewModel.IsLike;

                    UnitOfWork.ContentLikeRepository.Update(contentLike);
                    UnitOfWork.Save();
                }
            }
            else
            {
                ContentLike oContentLike = new ContentLike()
                {
                    UserId    = userId,
                    ContentId = contentId,
                    IsLike    = likeInputViewModel.IsLike,
                    IsActive  = true
                };
                UnitOfWork.ContentLikeRepository.Insert(oContentLike);
                UnitOfWork.Save();
            }

            return(true);
        }