Exemplo n.º 1
0
 public BusinessVideoVM(BusinessVideo bo)
 {
     this.Id              = bo.ID;
     this.ObjectId        = bo.RelevanceObjectID.ToString();
     this.FileDisplayName = bo.Name;
     this.FilePath        = bo.UploadPath;
 }
Exemplo n.º 2
0
        /// <summary>
        /// 根据传入 CourseItemContent 的 Id 获取 CourseItemContentVM
        /// </summary>
        /// <returns></returns>
        public async Task <ArticleVM> DeleteAttachmentFiles(Guid id, Guid businessFileId)
        {
            _businessFileService.DeleteAndSave(businessFileId);

            var boVM = await GetVM(id);

            // 处理附件
            var video = _businessVideoService.GetSingleBy(x => x.RelevanceObjectID == id);

            if (video == null)
            {
                video = new BusinessVideo();
            }
            boVM.Video = new BusinessVideoVM(video);

            var files = await _businessFileService.GetAllAsyn(x => x.RelevanceObjectID == id);

            boVM.FileCollection = new List <BusinessFileVM>();
            foreach (var item in files)
            {
                boVM.FileCollection.Add(new BusinessFileVM(item));
            }

            return(boVM);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 根据传入 CourseItem 的 Id 获取 CourseItemContentVM
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <CourseItemContentVM> GetCourseItemContentVM(Guid id)
        {
            // 初始化数据对象
            var bo             = _boRepository.GetSingle(id, x => x.ParentCourseItem, y => y.Course, w => w.CourseItemContent, z => z.Creator);
            var content        = bo.CourseItemContent;
            var contentFactory = new CourseItemContentVMService(_userManager, _courseItemContentRepository, _boRepository);
            var contentVM      = contentFactory.GetVM(content.Id);

            if (contentVM == null)
            {
                contentVM = new CourseItemContentVM();
            }
            else
            {
                contentVM.CourseID       = bo.Course.Id.ToString();
                contentVM.CourseName     = bo.Course.Name;
                contentVM.CourseItemID   = bo.Id.ToString();
                contentVM.CourseItemName = bo.Name;
            }

            // 处理附件
            var video = _businessVideoService.GetSingleBy(x => x.RelevanceObjectID == content.Id);

            if (video == null)
            {
                video = new BusinessVideo();
            }
            contentVM.Video = new BusinessVideoVM(video);

            var images = await _businessImageService.GetAllAsyn(x => x.RelevanceObjectID == content.Id);

            contentVM.ImageCollection = new List <BusinessImageVM>();
            foreach (var item in images)
            {
                contentVM.ImageCollection.Add(new BusinessImageVM(item));
            }

            var files = await _businessFileService.GetAllAsyn(x => x.RelevanceObjectID == content.Id);

            contentVM.FileCollection = new List <BusinessFileVM>();
            foreach (var item in files)
            {
                contentVM.FileCollection.Add(new BusinessFileVM(item));
            }

            return(contentVM);
        }
        public async Task <IActionResult> VideoSave(string id)
        {
            var    files           = Request.Form.Files;
            long   size            = files.Sum(f => f.Length);
            string webRootPath     = _HostingEnvironment.WebRootPath;
            string contentRootPath = _HostingEnvironment.ContentRootPath;

            foreach (var formFile in files)
            {
                if (formFile.Length > 0)
                {
                    string fileExt     = _GetFileSuffix(formFile.FileName); // 文件扩展名,不含“.”
                    long   fileSize    = formFile.Length;                   // 获得文件大小,以字节为单位
                    string newFileName = id + "_" + formFile.FileName;      // 生成新的文件名
                    var    filePath    = webRootPath + "/uploadFiles/videos/" + newFileName;
                    using (var stream = new FileStream(filePath, FileMode.Create))
                    {
                        await formFile.CopyToAsync(stream);
                    }

                    // 处理一个关联对象只能拥有一个视频
                    var videoBo = await _businessVideoService.GetSingleAsyn(Guid.Parse(id));

                    if (videoBo == null)
                    {
                        videoBo = new BusinessVideo();
                        videoBo.RelevanceObjectID = Guid.Parse(id);
                        videoBo.Name             = formFile.FileName;
                        videoBo.UploadFileSuffix = fileExt;
                        videoBo.UploadPath       = "/uploadFiles/videos/" + newFileName;
                    }
                    else
                    {
                        videoBo.RelevanceObjectID = Guid.Parse(id);
                        videoBo.Name             = formFile.FileName;
                        videoBo.UploadFileSuffix = fileExt;
                        videoBo.UploadPath       = "/uploadFiles/videos/" + newFileName;
                    }
                    await _businessVideoService.AddOrEditAndSaveAsyn(videoBo);
                }
            }

            return(Ok(new { count = files.Count, size }));
        }
Exemplo n.º 5
0
        /// <summary>
        /// 根据传入 CourseItemContent 的 Id 获取 CourseItemContentVM
        /// </summary>
        /// <returns></returns>
        public async Task <CourseItemContentVM> DeletCourseItemContentFile(Guid id, Guid businessFileId)
        {
            _businessFileService.DeleteAndSave(businessFileId);

            var contentFactory = new CourseItemContentVMService(_userManager, _courseItemContentRepository, _boRepository);
            var contentVM      = contentFactory.GetVM(id);
            var bo             = _boRepository.GetAllIncluding(x => x.ParentCourseItem, y => y.Course, w => w.CourseItemContent, z => z.Creator).Where(x => x.CourseItemContent.Id == id).FirstOrDefault();

            contentVM.CourseID       = bo.Course.Id.ToString();
            contentVM.CourseName     = bo.Course.Name;
            contentVM.CourseItemID   = bo.Id.ToString();
            contentVM.CourseItemName = bo.Name;

            // 处理附件
            var video = _businessVideoService.GetSingleBy(x => x.RelevanceObjectID == id);

            if (video == null)
            {
                video = new BusinessVideo();
            }
            contentVM.Video = new BusinessVideoVM(video);

            var images = await _businessImageService.GetAllAsyn(x => x.RelevanceObjectID == id);

            contentVM.ImageCollection = new List <BusinessImageVM>();
            foreach (var item in images)
            {
                contentVM.ImageCollection.Add(new BusinessImageVM(item));
            }

            var files = await _businessFileService.GetAllAsyn(x => x.RelevanceObjectID == id);

            contentVM.FileCollection = new List <BusinessFileVM>();
            foreach (var item in files)
            {
                contentVM.FileCollection.Add(new BusinessFileVM(item));
            }

            return(contentVM);
        }