Exemplo n.º 1
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();
        }
Exemplo n.º 2
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();
        }
Exemplo n.º 3
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();
        }
Exemplo n.º 4
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();
        }
Exemplo n.º 5
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();
        }