Пример #1
0
        public bool Check(bool likeDislike, long userId, long commentId)
        {
            LikeDislikeComment exist = _context.LikeDislikeComments.Where(ld => ld.Deleted == false &&
                                                                          ld.Owner.Id == userId &&
                                                                          ld.Comment.Id == commentId).
                                       SingleOrDefault(ld => ld.LikeOrDislike == likeDislike);

            if (exist == null)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Пример #2
0
        public static LikeCommentDTO ConvertCommentToDTO(LikeDislikeComment likeDislikeComment)
        {
            string likeDislike = "";

            if (likeDislikeComment.LikeOrDislike == true)
            {
                likeDislike = "Like";
            }
            else
            {
                likeDislike = "false";
            }
            LikeCommentDTO newDto = new LikeCommentDTO
            {
                Id            = likeDislikeComment.Id,
                LikeOrDislike = likeDislike,
                CreationDate  = likeDislikeComment.CreationDate.ToString("dd.mm.yyyy"),
                Owner         = UserForVideoComment.ConvertUserForVideoComment(likeDislikeComment.Owner),
                Comment       = CommentForUserDTO.SingleConvertCommentToDTO(likeDislikeComment.Comment)
            };

            return(newDto);
        }
Пример #3
0
 public LikeDislikeComment Add(LikeDislikeComment likeDislike)
 {
     _context.Add(likeDislike);
     _context.SaveChanges();
     return(likeDislike);
 }
Пример #4
0
        public IActionResult DislikeComment(long id)
        {
            var loggedInUserId = HttpContext.Session.GetString("LoggedInUserId");
            var contentType    = Request.ContentType;

            if (loggedInUserId == null)
            {
                if (contentType == null)
                {
                    return(Json("You need to login first"));
                }
                else
                {
                    return(StatusCode(401));
                }
            }
            User    user    = _userData.GetById(long.Parse(loggedInUserId));
            Comment comment = _commentData.GetById(id);

            if (user == null || comment == null)
            {
                if (contentType == null)
                {
                    return(Json("Bad request"));
                }
                else
                {
                    return(BadRequest());
                }
            }
            if (user.Blocked == true)
            {
                if (contentType == null)
                {
                    return(Json("Your account is blocked"));
                }
                else
                {
                    return(StatusCode(401));
                }
            }
            if (_likeCommentData.Check(false, user.Id, comment.Id))
            {
                return(Json("Already disliked"));
            }
            LikeDislikeComment likeDislikeComment = new LikeDislikeComment();

            likeDislikeComment.LikeOrDislike = false;
            likeDislikeComment.Owner         = user;
            likeDislikeComment.Comment       = comment;
            likeDislikeComment.CreationDate  = DateTime.Today;
            likeDislikeComment = _likeCommentData.Add(likeDislikeComment);
            comment.NumberOfDislikes++;
            _commentData.Update(comment);

            if (contentType != null)
            {
                if (contentType.Equals("application/json"))
                {
                    LikeCommentDTO likeCommentDTO = LikeCommentDTO.ConvertCommentToDTO(likeDislikeComment);
                    return(Json(likeCommentDTO));
                }
                else if (contentType.Equals("text/html"))
                {
                    //return View("VideoPage", singleVideoDTO);
                }
                return(StatusCode(415));
            }
            return(Json("Success"));
        }