예제 #1
0
        /// <summary>
        /// 保存多文件上传
        /// </summary>
        /// <param name="currentUserId">当前用户对象</param>
        /// <param name="modelId">关联的其他表Id</param>
        /// <param name="fileType">文件类型枚举</param>
        /// <param name="fileUpload">上传文件路径</param>
        /// <param name="fileIds">文件Id(如果是修改就可能有Id),可空</param>
        /// <param name="videoInfoList">视频的详情</param>
        /// <returns></returns>
        public List <Files> SaveMultUploadFile(long currentUserId, string modelId, FileTypesEnum fileType, List <string> fileUpload, List <int> fileIds, List <string> videoInfoList = null)
        {
            var          oldFiles       = _fileAppService.GetFilesListByCategoryIdAndType(modelId.ToString(), fileType.ToString());
            bool         canCommit      = false;
            List <Files> deleteFileList = new List <Files>();//删除的图片

            for (int i = oldFiles.Count - 1; i >= 0; i--)
            {
                if (fileIds == null || fileIds.Contains(oldFiles[i].Id) == false)
                {
                    _fileAppService.Delete(oldFiles[i]);
                    deleteFileList.Add(oldFiles[i]);//记录删除的图片
                    oldFiles.RemoveAt(i);
                    canCommit = true;
                }
            }
            if (fileUpload.IsNotNull() && fileUpload.Any())
            {
                var files = oldFiles.Select(o => o.Url).ToArray();
                for (int i = 0; i < fileUpload.Count; i++)
                {
                    var o = fileUpload[i];
                    if (files.Contains(o.Trim()) == false)
                    {
                        var f = BindUploadFiles(o, modelId.ToString(), fileType, currentUserId, false);
                        if (f.IsNotNull())
                        {
                            fileUpload[i] = f.Url;
                            if (videoInfoList.IsNotEmpty())
                            {
                                f.Description = videoInfoList[i];
                            }
                            oldFiles.Add(f);
                        }
                    }
                }
                canCommit = true;
            }
            if (canCommit)
            {
                if (oldFiles.Any())
                {
                    int i = 1;
                    foreach (var o in oldFiles)
                    {
                        o.SortNo = i++;
                    }
                    _fileAppService.Update(oldFiles);
                }
                foreach (var item in deleteFileList)//移动删除的文件
                {
                    MoveToRecycleAsync(item.Url);
                }
            }
            return(oldFiles);
        }