Beispiel #1
0
        public async Task DeleteLectureAsync(int lectureId)
        {
            // 1 get user, lecture, section data
            var user = await GetCurrentUser();

            var lecture = await _lectureRepository.GetLectureAsync(lectureId);

            if (lecture == null)
            {
                throw new NotFoundException("lecture not found");
            }
            var section = await _sectionRepository.GetSectionAsync(lecture.SectionId);

            if (section == null)
            {
                throw new NotFoundException("section not found");
            }
            // 2. remove the lecture from database
            section.RemoveLecture(user, lectureId);
            // 3. remove all videos from vimeo
            var vimeoVideoIds = lecture.Contents.Where(c => c.Video != null).Select(c => c.Video.VimeoId);

            foreach (var vimeoVideoId in vimeoVideoIds)
            {
                var deleteVideoUrl = string.Format(_vimeoConfig.DeleteVideoUrl, vimeoVideoId);
                await VimeoHelper.VideoDeleteAsync(_vimeoConfig.Token, deleteVideoUrl);
            }
            // 4. save database
            await _sectionRepository.SaveAsync();
        }
Beispiel #2
0
        public async Task DeleteSectionAsync(int sectionId)
        {
            // 1. get current user
            var user = await GetCurrentUser();

            // 2. get section
            var section = await _sectionRepository.GetSectionAsync(sectionId);

            if (section == null)
            {
                throw new NotFoundException("section not found");
            }
            // 2. get course by courseId
            var course = await _courseRepository.GetCourseAsync(section.CourseId, false);

            if (course == null)
            {
                throw new NotFoundException("Course not found");
            }
            // 3. remove section by sectionId
            course.RemoveSection(user, sectionId);
            // 4. remove all vimeo video in this section
            var vimeoVideoIds = section.Lectures.SelectMany(l => l.Contents).Where(c => c.Video != null).Select(c => c.Video.VimeoId);

            foreach (var vimeoVideoId in vimeoVideoIds)
            {
                var deleteVideoUrl = string.Format(_vimeoConfig.DeleteVideoUrl, vimeoVideoId);
                await VimeoHelper.VideoDeleteAsync(_vimeoConfig.Token, deleteVideoUrl);
            }
            // 5. save db change & done
            await _courseRepository.SaveAsync();
        }
Beispiel #3
0
        private void ActualizarThumbs()
        {
            var videosSinThumb = db.Videos.Where(v => v.ThumbNail.Contains("default") || v.ThumbNail.Contains(""));

            foreach (var vid in videosSinThumb)
            {
                VimeoHelper.GetThumbnail(vid.UrlVideo, vid.VideoId);
            }
        }
Beispiel #4
0
        public async Task <CourseDto> UpdateCourseAsync(int courseId, CourseUpdateRequestDto request)
        {
            // 1. get current user
            var user = await GetCurrentUser();

            if (user == null)
            {
                throw new NotFoundException("user not found");
            }
            // 2. get EntityAttributes
            IList <EntityAttribute> entityAttributes = null;

            if (request.CourseAttributeIds != null)
            {
                entityAttributes = await _entityAttributeRepository.GetEntityAttributeByIdsAsync(request.CourseAttributeIds);
            }
            // 3. get course by courseId
            var course = await _courseRepository.GetCourseAsync(courseId, false);

            if (course == null)
            {
                throw new NotFoundException("Course not found");
            }
            // 4. update vimeo album if course title changed
            if (request.Title != null)
            {
                var editAlbumUrl = string.Format(_vimeoConfig.EditAlbumUrl, course.VimeoAlbumId);
                await VimeoHelper.AlbumEditPatchAsync(_vimeoConfig.Token, editAlbumUrl, request.Title);
            }
            // 5. update course
            string courseImageUrl = null;

            if (request.CoverPageImage != null)
            {
                courseImageUrl = _storageConnectionConfig.Url + _storageConnectionConfig.CourseImageContainerName + "/" + request.CoverPageImage;
            }
            course.Update(
                user,
                request.Title,
                request.Subtitle,
                request.Description,
                0,
                request.Prerequisites,
                request.Refferences,
                request.TargetStudents,
                request.UnitPrice,
                request.DiscountAmount,
                request.DiscountPercent,
                courseImageUrl,
                entityAttributes
                );
            // 5. save db change
            await _courseRepository.SaveAsync();

            // 6. return
            return(Mapper.Map <CourseDto>(course));
        }
Beispiel #5
0
        public async Task <VidoeTextTracksResponseDto> GetAllTextTracks(int videoId)
        {
            var user = await GetCurrentUser();

            var video = await _videoRepository.GetVideoByIdAsync(videoId);

            if (video == null)
            {
                throw new NotFoundException("Video not found");
            }
            var getAllTextTracksUrl = string.Format(_vimeoConfig.GetTextTracksUrl, video.VimeoId);

            return(await VimeoHelper.TextTracksGetAllAsync(_vimeoConfig.Token, getAllTextTracksUrl));
        }
Beispiel #6
0
        public async Task <VimeoVidoeResponseDto> GetVimeoVideoStutasByIdAsync(int videoId)
        {
            var user = await GetCurrentUser();

            var video = await _videoRepository.GetVideoByIdAsync(videoId);

            if (video == null)
            {
                throw new NotFoundException("Video not found");
            }
            var getVideoUrl         = string.Format(_vimeoConfig.GetVideoUrl, video.VimeoId);
            var vidoeUploadResponse = await VimeoHelper.VideoGetAsync(_vimeoConfig.Token, getVideoUrl);

            vidoeUploadResponse.VideoId = video.Id;
            return(vidoeUploadResponse);
        }
Beispiel #7
0
        public async Task DeleteTextTrackAsync(int videoId, int textTrackId)
        {
            // 1. get user & video
            var user = await GetCurrentUser();

            var video = await _videoRepository.GetVideoByIdAsync(videoId);

            if (video == null)
            {
                throw new NotFoundException("Video not found");
            }
            // 2. check course status
            video.Content.Lecture.Section.Course.CourseUpdateValidate(user);
            // 3. delete TT from vimeo
            var deleteTextTrackUrl = string.Format(_vimeoConfig.DeleteTextTrackUrl, video.VimeoId, textTrackId);
            await VimeoHelper.TextTrackDeleteAsync(_vimeoConfig.Token, deleteTextTrackUrl);
        }
Beispiel #8
0
        public async Task <VidoeTextTracksUploadUploadTicketResponseDto> CreateTextTracksUploadTicketAsync(int videoId, VidoeTextTracksUploadTicketRequestDto request)
        {
            // 1. get user & video
            var user = await GetCurrentUser();

            var video = await _videoRepository.GetVideoByIdAsync(videoId);

            if (video == null)
            {
                throw new NotFoundException("Video not found");
            }
            // 2. check course status
            video.Content.Lecture.Section.Course.CourseUpdateValidate(user);
            // 3. get TT upload ticket
            var uploadTextTrackTicketRequestUrl = string.Format(_vimeoConfig.UploadTextTrackTicketRequestUrl, video.VimeoId);

            return(await VimeoHelper.TextTrackUploadTicketCreatePostAsync(_vimeoConfig.Token, uploadTextTrackTicketRequestUrl, request.LanguageCode, request.Name));
        }
Beispiel #9
0
        // GET: Admin/Videos/Delete/5
        public ActionResult Delete(int id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Video Video = db.Videos.Find(id);

            if (Video == null)
            {
                return(HttpNotFound());
            }

            VimeoHelper.DeleteFiles(Video.UrlVideo);

            //Eliminar subtema
            db.Videos.Remove(Video);
            db.SaveChanges();
            return(RedirectToAction("Index", new { }));
        }
Beispiel #10
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);
        }
Beispiel #11
0
        public async Task DeletePreviewVideoAsync(int courseId)
        {
            var user = await GetCurrentUser();

            var course = await _courseRepository.GetCourseAsync(courseId, false);

            if (course == null)
            {
                throw new NotFoundException("course not found");
            }
            if (course.PreviewVideo == null)
            {
                throw new NotFoundException("course preview video not found");
            }
            course.CourseUpdateValidate(user);
            var deleteVideoUrl = string.Format(_vimeoConfig.DeleteVideoUrl, course.PreviewVideo.VimeoId);
            await VimeoHelper.VideoDeleteAsync(_vimeoConfig.Token, deleteVideoUrl);

            course.DeletePreviewVideo();
            await _courseRepository.SaveAsync();
        }
Beispiel #12
0
        public ActionResult Create(VideoCreateViewModel viewModel)
        {
            //fichero pdf
            //"~/media/upload/Videos_puntos/"

            if (ModelState.IsValid)
            {
                viewModel.Video.Fecha = DateTime.Now;

                db.Videos.Add(viewModel.Video);
                db.SaveChanges();


                string nameAndLocation = "~/media/upload/VideosTemp/" + viewModel.Video.VideoId + "_" + viewModel.File.FileName.Replace(" ", "");
                viewModel.File.SaveAs(Server.MapPath(nameAndLocation));


                string resultado = VimeoHelper.UploadVideo(nameAndLocation, viewModel.Video.VideoId);
                string fullPath  = Request.MapPath(nameAndLocation);
                if (System.IO.File.Exists(fullPath))
                {
                    System.IO.File.Delete(fullPath);
                }
                if (resultado != "OK")
                {
                    ModelState.AddModelError("File", resultado);

                    db.Videos.Remove(viewModel.Video);
                    db.SaveChanges();
                    return(View(viewModel));
                }



                return(RedirectToAction("Index", new { }));
            }
            return(View(viewModel));
        }
Beispiel #13
0
        public async Task DeleteCourseAsync(int courseId)
        {
            // 1. get current user
            var user = await GetCurrentUser();

            // 2. get course by courseId and course attributes
            var course = await _courseRepository.GetCourseAsync(courseId, false);

            if (course == null)
            {
                throw new NotFoundException("Course not found");
            }
            // 3. delete all vimeo videos in this course
            var vimeoVideoIds = course.Sections
                                .SelectMany(s => s.Lectures)
                                .SelectMany(l => l.Contents)
                                .Where(c => c.Video != null)
                                .Select(c => c.Video.VimeoId)
                                .ToList();

            if (course.PreviewVideo != null)
            {
                vimeoVideoIds.Add(course.PreviewVideo.VimeoId);
            }

            foreach (var vimeoVideoId in vimeoVideoIds)
            {
                var deleteVideoUrl = string.Format(_vimeoConfig.DeleteVideoUrl, vimeoVideoId);
                await VimeoHelper.VideoDeleteAsync(_vimeoConfig.Token, deleteVideoUrl);
            }
            // 4. remove vimeo album
            var deleteAlbumUrl = string.Format(_vimeoConfig.DeleteAlbumUrl, course.VimeoAlbumId);
            await VimeoHelper.AlbumDeleteAsync(_vimeoConfig.Token, deleteAlbumUrl);

            // 5.delete the course
            _courseRepository.Remove(course);
            await _courseRepository.SaveAsync();
        }
Beispiel #14
0
        public async Task <VimeoVidoeResponseDto> CreatePreviewVideoUploadTicketAsync(int courseId, VidoeUploadTicketRequestDto request)
        {
            var user = await GetCurrentUser();

            var course = await _courseRepository.GetCourseAsync(courseId, false);

            if (course == null)
            {
                throw new NotFoundException("course not found");
            }
            course.CourseUpdateValidate(user);
            var vimeoVideoTitle     = course.Id + "-preview";
            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.");
            }
            var vimeoAlbumId = 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 = course.AddPreviewVideo(vimeoVideoId);
            await _courseRepository.SaveAsync();

            // 6 return the upload ticket
            vidoeUploadResponse.VideoId = video.Id;
            return(vidoeUploadResponse);
        }
Beispiel #15
0
        public async Task DeleteVideoAsync(int videoId)
        {
            // 1. get user & video info
            var user = await GetCurrentUser();

            var video = await _videoRepository.GetVideoByIdAsync(videoId);

            if (video == null)
            {
                throw new NotFoundException("video not found");
            }
            // 2. check course status
            video.Content.Lecture.Section.Course.CourseUpdateValidate(user);
            // 3. Update Course duration
            video.CleanUp();
            // 4. remove video from database
            _videoRepository.Remove(video.Content);
            // 5. remove video from vimeo
            var deleteVideoUrl = string.Format(_vimeoConfig.DeleteVideoUrl, video.VimeoId);
            await VimeoHelper.VideoDeleteAsync(_vimeoConfig.Token, deleteVideoUrl);

            // 6. save db
            await _videoRepository.SaveAsync();
        }
Beispiel #16
0
        // Synchronize database video with vimeo video
        public async Task SynchronizeVideoAsync(int videoId)
        {
            // 1. get user & video info
            var user = await GetCurrentUser();

            var video = await _videoRepository.GetVideoByIdAsync(videoId);

            if (video == null)
            {
                throw new NotFoundException("video not found");
            }
            // 2. check course status
            video.Content.Lecture.Section.Course.CourseUpdateValidate(user);
            // 3. get video duration from vimeo
            var getVideoUrl = string.Format(_vimeoConfig.GetVideoUrl, video.VimeoId);
            var vimeoVideo  = await VimeoHelper.VideoGetAsync(_vimeoConfig.Token, getVideoUrl);

            // 4. update video duration in database
            video.Update(null, vimeoVideo.Duration);
            await _videoRepository.SaveAsync();

            // 5. add videoId to vimeo
            await VimeoHelper.VideoEditPatchAsync(_vimeoConfig.Token, getVideoUrl, videoId.ToString());
        }