示例#1
0
        public async Task <IActionResult> CommentLike(CommentLikeCreateDto commentLikeCreateDto)
        {
            var isThere = await _commentLikeService.LikeExists(commentLikeCreateDto);

            if (isThere == "0")
            {
                var entity = await _commentLikeService.Add(commentLikeCreateDto);

                if (entity.Success)
                {
                    // var result = await _commentLikeService.GetCommentLike(commentLikeCreateDto.CommentId);
                    // result.Data.Message = entity.Message;
                    return(Ok(entity.Message));
                }
            }
            if (isThere == "1")
            {
                var delete = await _commentLikeService.Delete(commentLikeCreateDto);

                if (delete.Success)
                {
                    var entity = await _commentLikeService.Add(commentLikeCreateDto);

                    if (entity.Success)
                    {
                        // var result = await _commentLikeService.GetCommentLike(commentLikeCreateDto.CommentId);
                        //result.Data.Message = entity.Message;
                        return(Ok(entity.Message));
                    }
                }
            }

            if (isThere == "2")
            {
                var entity = await _commentLikeService.Delete(commentLikeCreateDto);

                if (entity.Success)
                {
                    return(Ok(entity.Message));
                }
            }
            return(BadRequest());
        }
        public async Task <string> LikeExists(CommentLikeCreateDto commentLike)
        {
            //daha önce commente like işlemi yapmış mı diye kontrol etmek için
            var isThere = await _commentLikeDal.GetList(x => x.CommentId == commentLike.CommentId && x.UserId == commentLike.userId);

            //kayıt yok demek direk ekleme işlemi yap
            if (isThere.Count == 0)
            {
                return("0");
            }
            var likeStatus = await _commentLikeDal.GetList(x => x.CommentId == commentLike.CommentId && x.UserId == commentLike.userId && x.LikeStatus == commentLike.LikeStatus);

            //gelen işlem dbde yoksa güncelleme yap demek
            if (likeStatus.Count == 0)
            {
                return("1");
            }
            //gelen data dbde varsa kaldırma işlemi yapılacak.
            return("2");
        }
        public async Task <IResult> Delete(CommentLikeCreateDto commentLike)
        {
            await _commentLikeDal.DeleteById(x => x.CommentId == commentLike.CommentId && x.UserId == commentLike.userId);

            return(new SuccessResult(Messages.CommentLikeDeleted));
        }
        public async Task <IResult> Add(CommentLikeCreateDto commentLike)
        {
            await _commentLikeDal.Add(new CommentLike { CommentId = commentLike.CommentId, UserId = commentLike.userId, LikeStatus = commentLike.LikeStatus });

            return(new SuccessResult(commentLike.LikeStatus == true ? "Yorumu beğendiniz" : "Yorumu beğenmediniz"));
        }