示例#1
0
        /// <summary>
        /// Add video to course.
        /// </summary>
        /// <param name="courseId"></param>
        /// <param name="video"></param>
        /// <returns></returns>
        public void AddVideoToCourse(string courseId, VideoMaterialInfo video)
        {
            var videoDb      = _mapper.Map <VideoMaterialInfo, VideoMaterialDb>(video);
            var courseVideos = _courseRepository.GetById(courseId).Videos;

            courseVideos.Add(videoDb);
        }
示例#2
0
        /// <summary>
        /// Create a new video.
        /// </summary>
        /// <param name="video"></param>
        /// <returns></returns>
        public async Task <Result <VideoMaterialInfo> > AddAsync(VideoMaterialInfo video, string courseId)
        {
            var videoDb = _mapper.Map <VideoMaterialInfo, VideoMaterialDb>(video);

            videoDb.Created  = DateTime.Now;
            videoDb.CourseId = courseId; //заменить на ID курса
            try
            {
                await _videoRepository.AddAsync(videoDb);

                return(Result <VideoMaterialInfo> .Ok(_mapper.Map <VideoMaterialInfo>(videoDb)));
            }
            catch (DbUpdateConcurrencyException e)
            {
                return((Result <VideoMaterialInfo>)Result.Fail($"Cannot save video. {e.Message}"));
            }
            catch (DbUpdateException e)
            {
                return((Result <VideoMaterialInfo>)Result.Fail($"Cannot save video. Duplicate field. {e.Message}"));
            }
            catch (DbEntityValidationException e)
            {
                return((Result <VideoMaterialInfo>)Result.Fail($"Invalid video. {e.Message}"));
            }
        }
示例#3
0
        /// <summary>
        /// Add video to course.
        /// </summary>
        /// <param name="course"></param>
        /// <param name="video"></param>
        /// <returns></returns>
        public Task <Result> AddVideoAsync(CourseInfo course, VideoMaterialInfo video)
        {
            var videoDb      = _mapper.Map <VideoMaterialInfo, VideoMaterialDb>(video);
            var courseVideos = _mapper.Map <CourseInfo, CourseDb>(course);

            try
            {
                courseVideos.Videos.Add(videoDb);
                return(Task.FromResult(Result.Ok()));
            }
            catch (DbUpdateConcurrencyException e)
            {
                return(Task.FromResult(Result.Fail($"Cannot add video to course. {e.Message}")));
            }
            catch (DbUpdateException e)
            {
                return(Task.FromResult(Result.Fail($"Cannot add video to course. Duplicate field. {e.Message}")));
            }
            catch (DbEntityValidationException e)
            {
                return(Task.FromResult(Result.Fail($"Invalid tag. {e.Message}")));
            }
        }
示例#4
0
        /// <summary>
        /// Update video.
        /// </summary>
        /// <param name="video"></param>
        /// <returns></returns>
        public async Task <Result <VideoMaterialInfo> > UpdateAsync(VideoMaterialInfo video)
        {
            var videoDb = _mapper.Map <VideoMaterialInfo, VideoMaterialDb>(video);

            try
            {
                await _videoRepository.UpdateAsync(videoDb);

                return(Result <VideoMaterialInfo> .Ok(_mapper.Map <VideoMaterialInfo>(videoDb)));
            }
            catch (DbUpdateConcurrencyException e)
            {
                return((Result <VideoMaterialInfo>)Result.Fail($"Cannot update video. {e.Message}"));
            }
            catch (DbUpdateException e)
            {
                return((Result <VideoMaterialInfo>)Result.Fail($"Cannot update video. Duplicate field. {e.Message}"));
            }
            catch (DbEntityValidationException e)
            {
                return((Result <VideoMaterialInfo>)Result.Fail($"Invalid video. {e.Message}"));
            }
        }
示例#5
0
        /// <summary>
        /// Remove video.
        /// </summary>
        /// <param name="video"></param>
        /// <returns></returns>
        public void Delete(VideoMaterialInfo video)
        {
            var videoDb = _mapper.Map <VideoMaterialInfo, VideoMaterialDb>(video);

            _videoRepository.Remove(videoDb);
        }
示例#6
0
        /// <summary>
        /// Create a new video.
        /// </summary>
        /// <param name="video"></param>
        /// <returns></returns>
        public void Add(VideoMaterialInfo video)
        {
            var videoDb = _mapper.Map <VideoMaterialInfo, VideoMaterialDb>(video);

            _videoRepository.Add(videoDb);
        }