示例#1
0
        public IActionResult EditVideo(int id)
        {
            var video       = _videos.GetById(id);
            var video_model = new VideoDetailModel
            {
                AssetId          = id,
                Title            = video.Title,
                Year             = video.Year,
                Cost             = video.Cost,
                Status           = video.Status.Name,
                NumberOfCopies   = video.NumberOfCopies,
                ImageUrl         = video.ImageUrl,
                AuthorOrDirector = video.Director
            };

            //return Content(mess);
            return(View(video_model));
        }
        public IActionResult Watch(string video)
        {
            var currentVideo = _videoService.GetById(video);

            Bundle <WatchVideoModel> model = new Bundle <WatchVideoModel>();

            if (currentVideo != null)
            {
                model.PageModel = new WatchVideoModel
                {
                    Video = new VideoViewModel
                    {
                        Id           = currentVideo.Id,
                        Title        = currentVideo.Title,
                        VideoUrl     = currentVideo.VideoUrl,
                        ThumbnailUrl = currentVideo.ThumbnailUrl,
                        GroupName    = currentVideo.GroupName,
                        Description  = currentVideo.Description,
                        ViewCount    = currentVideo.ViewCount,
                        Duration     = currentVideo.Duration.TotalHours >= 1 ? currentVideo.Duration.ToString("hh\\:mm\\:ss")
                    : currentVideo.Duration.Minutes >= 1 ? currentVideo.Duration.ToString($"mm\\:ss")
                    : currentVideo.Duration.ToString("ss"),
                        CreateUser = new UserViewModel
                        {
                            UserName  = currentVideo.CreateUser.UserName,
                            FirstName = currentVideo.CreateUser.FirstName,
                            LastName  = currentVideo.CreateUser.LastName,
                            AvatarUrl = currentVideo.CreateUser.AvatarUrl
                        },
                        CreatedDate = currentVideo.CreatedDate,
                        UpdateUser  = new UserViewModel
                        {
                            UserName  = currentVideo.UpdateUser.UserName,
                            FirstName = currentVideo.UpdateUser.FirstName,
                            LastName  = currentVideo.UpdateUser.LastName,
                            AvatarUrl = currentVideo.UpdateUser.AvatarUrl
                        },
                        UpdatedDate = currentVideo.UpdatedDate
                    }
                };

                model.PageModel.VideosFromTheSameYear = _videoService.GetByYear(currentVideo.Year)
                                                        .Where(v => v.State.StateName == "Active" && v.Id != video)
                                                        .OrderByDescending(v => v.CreatedDate)
                                                        .ToList().Select(v => new VideoViewModel
                {
                    Id           = v.Id,
                    Title        = v.Title,
                    VideoUrl     = v.VideoUrl,
                    ThumbnailUrl = v.ThumbnailUrl,
                    GroupName    = v.GroupName,
                    Description  = v.Description,
                    ViewCount    = v.ViewCount,
                    Duration     = v.Duration.TotalHours >= 1 ? v.Duration.ToString("hh\\:mm\\:ss")
                    : v.Duration.Minutes >= 1 ? v.Duration.ToString($"mm\\:ss")
                    : v.Duration.ToString("ss"),
                    CreateUser = new UserViewModel
                    {
                        UserName  = v.CreateUser.UserName,
                        FirstName = v.CreateUser.FirstName,
                        LastName  = v.CreateUser.LastName,
                        AvatarUrl = v.CreateUser.AvatarUrl
                    },
                    CreatedDate = v.CreatedDate,
                    UpdateUser  = new UserViewModel
                    {
                        UserName  = v.UpdateUser.UserName,
                        FirstName = v.UpdateUser.FirstName,
                        LastName  = v.UpdateUser.LastName,
                        AvatarUrl = v.UpdateUser.AvatarUrl
                    },
                    UpdatedDate = v.UpdatedDate
                }).ToArray();
                var ip = _accessor.HttpContext.Connection.RemoteIpAddress;

                if (User.Identity.Name == null)
                {
                    _videoService.ViewVideo(video, ip);
                }
                else
                {
                    _videoService.ViewVideo(video, ip, User.Identity.Name);
                }

                ViewData["Title"] = model.PageModel.Video.Title;
            }
            else
            {
                model.PageModel   = new WatchVideoModel();
                ViewData["Title"] = "Video Bulunamadı";
            }
            return(View(model));
        }