Beispiel #1
0
        public IActionResult PostComment(long id, string description)
        {
            Comment comment        = new Comment();
            var     loggedInUserId = HttpContext.Session.GetString("LoggedInUserId");

            if (loggedInUserId == null)
            {
                return(StatusCode(401));
            }
            User  user  = _userData.GetById(long.Parse(loggedInUserId));
            Video video = _videoData.GetById(id);

            if (user == null || video == null)
            {
                return(BadRequest());
            }
            if (user.Blocked == true)
            {
                return(StatusCode(401));
            }
            comment.User         = user;
            comment.Video        = video;
            comment.Description  = description;
            comment.CreationDate = DateTime.Today;
            comment = _commentData.Create(comment);
            CommentDTO commentDTO  = CommentDTO.ConvertCommentToDTO(comment);
            var        contentType = Request.ContentType;

            if (contentType != null)
            {
                if (contentType.Equals("application/json"))
                {
                    return(Json(commentDTO));
                }
                else if (contentType.Equals("text/html"))
                {
                    //return View("VideoPage", singleVideoDTO);
                }
                else if (contentType.Equals("application/x-www-form-urlencoded; charset=UTF-8"))
                {
                    return(Json("Success"));
                }
                return(StatusCode(415));
            }
            return(Json(commentDTO));
        }
        public ActionResult CreateComment(Comment comment)
        {
            if (UsersHelper.LoggedInUserUsername(Session) == null)
            {
                return(null);
            }
            var currentUser = UsersHelper.LoggedInUserUsername(Session);

            if (currentUser == null)
            {
                return(null);
            }
            comment.CommentOwner = currentUser;
            comment.DatePosted   = DateTime.Now;
            _commentsRepository.CreateComment(comment);

            ViewBag.Values = Comment.CommentsSortOrderSelectList();
            var cdto = CommentDTO.ConvertCommentToDTO(comment);

            return(PartialView("SingleComment", cdto));
        }