예제 #1
0
        public IActionResult EditComment(long id, string description)
        {
            var loggedInUserId = HttpContext.Session.GetString("LoggedInUserId");

            if (loggedInUserId == null)
            {
                return(StatusCode(401));
            }
            User    user    = _userData.GetById(long.Parse(loggedInUserId));
            Comment comment = _commentData.GetById(id);

            if (user == null || comment == null)
            {
                return(BadRequest());
            }
            comment.Description = description;
            comment.Video       = _videoData.GetById(comment.VideoId);
            comment             = _commentData.Update(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));
        }