Exemplo n.º 1
0
        public async Task <ActionResultResponse <VideoDetailViewModel> > GetDetail(string tenantId, string videoId)
        {
            var info = await _videoRepository.GetInfo(videoId);

            if (info == null)
            {
                return(new ActionResultResponse <VideoDetailViewModel>(-1, _websiteResourceService.GetString("Video does not exists.")));
            }

            if (info.TenantId != tenantId)
            {
                return(new ActionResultResponse <VideoDetailViewModel>(-2, _sharedResourceService.GetString(ErrorMessage.NotHavePermission)));
            }

            var apiUrls = _configuration.GetApiUrl();

            if (apiUrls == null)
            {
                return(new ActionResultResponse <VideoDetailViewModel>(-3,
                                                                       _sharedResourceService.GetString(
                                                                           "Missing some configuration. Please contact with administrator.")));
            }

            var resultTag = await new HttpClientService()
                            .GetAsync <List <SubjectTagViewModel> >($"{apiUrls.CoreApiUrl}/tags/{tenantId}/{videoId}");


            var videoTranslations = await _videoTranslationRepository.GetsVideoId(videoId);

            var videoDetail = new VideoDetailViewModel
            {
                Id                   = info.Id,
                AlbumId              = info.AlbumId,
                Thumbnail            = info.Thumbnail,
                Url                  = info.Url,
                Order                = info.Order,
                Type                 = info.Type,
                VideoLinkId          = info.VideoLinkId,
                IsActive             = info.IsActive,
                ConcurrencyStamp     = info.ConcurrencyStamp,
                IsHomePage           = info.IsHomePage,
                LastUpdateIsHomePage = info.LastUpdateIsHomePage,

                VideoTranslations = videoTranslations.Select(x => new VideoTranslationViewModel
                {
                    LanguageId  = x.LanguageId,
                    Title       = x.Title,
                    Description = x.Description,
                    Tags        = resultTag?.Where(t => t.LanguageId == x.LanguageId).ToList()
                }).ToList()
            };

            return(new ActionResultResponse <VideoDetailViewModel>
            {
                Code = 1,
                Data = videoDetail
            });
        }
Exemplo n.º 2
0
        public async Task <ActionResultResponse <AlbumDetailViewModel> > GetDetail(string tenantId, string albumId)
        {
            var info = await _albumRepository.GetInfo(albumId);

            if (info == null)
            {
                return(new ActionResultResponse <AlbumDetailViewModel>(-1, _websiteResourceService.GetString("Album does not exists.")));
            }

            if (info.TenantId != tenantId)
            {
                return(new ActionResultResponse <AlbumDetailViewModel>(-2, _sharedResourceService.GetString(ErrorMessage.NotHavePermission)));
            }

            var albumTranslations = await _albumTranslationRepository.GetsByAlbumId(albumId);

            var albumDetail = new AlbumDetailViewModel
            {
                Id               = info.Id,
                IsActive         = info.IsActive,
                ConcurrencyStamp = info.ConcurrencyStamp,
                Translations     = albumTranslations,
                Type             = info.Type,
                Thumbnail        = info.Thumbnail,
                IsPublic         = info.IsPublic,
                Photos           = info.Type == AlbumType.Photo ? await _photoRepository.GetsByAlbumId(tenantId, albumId, true) : null,
            };

            if (info.Type == AlbumType.Video)
            {
                var videos = await _videoRepository.GetsByAlbumId(albumId, true);

                if (videos.Any())
                {
                    foreach (var video in videos)
                    {
                        video.Translations = await _videoTranslationRepository.GetsVideoId(video.Id);
                    }
                }
                albumDetail.Videos = videos;
            }

            return(new ActionResultResponse <AlbumDetailViewModel>
            {
                Code = 1,
                Data = albumDetail
            });
        }