コード例 #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));
        }
コード例 #2
0
        public IActionResult GetOneVideoById(long id)
        {
            Video video = _videoData.GetById(id);

            if (video == null)
            {
                return(NotFound());
            }
            return(Json(video));
        }
コード例 #3
0
ファイル: SearchController.cs プロジェクト: BulatL/Youtube2
        public IActionResult SearchAll(string searchText)
        {
            var loggedInUserRole = HttpContext.Session.GetString("LoggedInUserRole");

            if (searchText == null)
            {
                searchText = "";
            }
            IEnumerable <Video>   videos   = new List <Video>();
            IEnumerable <Comment> comments = new List <Comment>();
            IEnumerable <User>    users    = new List <User>();

            users    = _userData.Search(searchText, null, "desc");
            comments = _commentData.Search(searchText, "desc");
            if (loggedInUserRole == null)
            {
                videos = _videoData.GetAllNoUser().Where(v => v.Name.Contains(searchText) ||
                                                         v.Description.Contains(searchText));
            }
            else
            {
                if (loggedInUserRole.Equals("0"))
                {
                    videos = _videoData.GetAllForAdmin().Where(v => v.Name.Contains(searchText) ||
                                                               v.Description.Contains(searchText));
                }
                else
                {
                    long loggedInUserId = long.Parse(HttpContext.Session.GetString("LoggedInUserId"));
                    videos = _videoData.GetAllForUser(loggedInUserId).
                             Where(v => v.Name.Contains(searchText) ||
                                   v.Description.Contains(searchText));
                }
            }
            if (videos.Count() > 0)
            {
                foreach (var v in videos)
                {
                    v.Owner = _userData.GetById(v.OwnerId);
                }
            }
            if (comments.Count() > 0)
            {
                foreach (var c in comments)
                {
                    c.User  = _userData.GetById(c.UserId);
                    c.Video = _videoData.GetById(c.VideoId);
                }
            }

            SearchViewModel searchViewModel = new SearchViewModel();

            searchViewModel.Users    = UserForAdminPage.ConvertDTO(users);
            searchViewModel.Comments = CommentDTO.ConvertCommenstToDTO(comments);
            searchViewModel.Videos   = VideoDTO.ConvertVideosToDTO(videos);
            var contentType = Request.ContentType;

            if (contentType != null)
            {
                if (contentType.Equals("application/json"))
                {
                    return(Json(searchViewModel));
                }
            }
            return(View("SearchPage", searchViewModel));
        }