Ejemplo n.º 1
0
        public async Task <ContentDto> CreateContentAsync(int lectureId, ContentCreateRequestDto request)
        {
            var user = await GetCurrentUser();

            if (user == null)
            {
                throw new NotFoundException("user not found");
            }

            var lecture = await _lectureRepository.GetLectureAsync(lectureId);

            if (lecture == null)
            {
                throw new NotFoundException("lecture not found");
            }

            // TODO: currently support Video only
            var content = lecture.AddContent(user, request.Title, request.Desctiption, request.VimeoId, request.DurationInSecond);

            await _lectureRepository.SaveAsync();

            return(Mapper.Map <ContentDto>(content));
        }
Ejemplo n.º 2
0
        public async Task <VimeoVidoeResponseDto> CreateVideoUploadTicketAsync(int lectureId, VidoeUploadTicketRequestDto request)
        {
            // 1. get user & lecture info
            var user = await GetCurrentUser();

            var lecture = await _lectureRepository.GetLectureAsync(lectureId);

            if (lecture == null)
            {
                throw new NotFoundException("lecture not found");
            }
            // 2. verify the course state and course author
            lecture.Section.Course.CourseUpdateValidate(user);
            // 3. gernerate the vimeo upload ticket
            var vimeoVideoTitle     = lecture.Section.Course.Id + "-" + lecture.Section.Id.ToString() + "-" + lecture.Id.ToString();
            var vidoeUploadResponse = await VimeoHelper.VideoUploadTicketCreatePostAsync(_vimeoConfig.Token, _vimeoConfig.UploadVideoTicketRequestUrl, request.FileSize, vimeoVideoTitle);

            var vimeoVideoId = new Uri(vidoeUploadResponse.Uri).Segments.Last();

            if (vimeoVideoId == null)
            {
                throw new VideoUpdateException("Cannot upload video because no vimeo video ID found, please contact our tech support.");
            }
            // 4. add the video into the course vimeo album
            var vimeoAlbumId = lecture.Section.Course.VimeoAlbumId;

            if (vimeoAlbumId == null)
            {
                throw new VideoUpdateException("Fail to add video into album because album ID not found, please contact our tech support.");
            }
            var addAlbumVideoUrl = string.Format(_vimeoConfig.AddAlbumVideoUrl, vimeoAlbumId, vimeoVideoId);
            await VimeoHelper.AddVideoToAlbum(_vimeoConfig.Token, addAlbumVideoUrl);

            // 5. add video metedata into database
            var video = lecture.AddVideoContent(user, request.Title, request.Desctiption, vimeoVideoId, request.DurationInSecond);
            await _lectureRepository.SaveAsync();

            vidoeUploadResponse.VideoId = video.Id;
            // 6 return the upload ticket
            return(vidoeUploadResponse);
        }
Ejemplo n.º 3
0
 public async Task <LectureDto> GetLectureByIdAsync(int lectureId)
 {
     return(Mapper.Map <LectureDto>(await _lectureRepository.GetLectureAsync(lectureId)));
 }