public Guid CreateArchivesManagerActive(string instaceId) { var projectId = instaceId.ToGuid(); var data = new CreateOrUpdateArchivesManagerInput(); data.Id = Guid.NewGuid(); var files = from f in _projectFileRepository.GetAll() join filetype in _aappraisalFileTypeRepository.GetAll() on f.AappraisalFileType equals filetype.Id where f.SingleProjectId == projectId select new { f.Id, f.FileName, f.FilePath, f.IsPaperFile, filetype.Name, f.PaperFileNumber }; var projectModel = _singleProjectInfoRepository.Get(projectId); data.ProjectId = projectModel.Id; foreach (var file in files) { //if(string.IsNullOrWhiteSpace(file.FileName)) // continue; var entity = new CreateOrUpdateArchivesFileInput() { FileName = file.FileName, Id = file.Id, FileType = file.Name, IsPaper = file.IsPaperFile, PaperNumber = file.PaperFileNumber }; if (!string.IsNullOrWhiteSpace(file.FileName)) { entity.Files = Newtonsoft.Json.JsonConvert.DeserializeObject <List <FileUploadFiles> >(file.FileName); } data.Files.Add(entity); } var archivesManager = new ArchivesManager(); archivesManager.Id = data.Id.Value; archivesManager.ArchivesName = projectModel.SingleProjectName + "-归档"; archivesManager.ProjectId = data.ProjectId; _archivesManagerRepository.InsertAsync(archivesManager); foreach (var file in data.Files) { var entity = new ArchivesFile(); file.Id = Guid.NewGuid(); file.ArchivesId = archivesManager.Id; file.MapTo(entity); _archivesFileRepository.Insert(entity); } return(archivesManager.Id); }
public async Task <GetArchivesManagerForEditOutput> GetArchivesForWFProjectWithId(string instanceId) { var id = instanceId.ToGuid(); var model = await _archivesManagerRepository.GetAsync(id); if (!model.ProjectId.HasValue) { throw new UserFriendlyException((int)ErrorCode.DataAccessErr, "数据异常"); } var projectId = model.ProjectId.Value; var projectModel = await _singleProjectInfoRepository.GetAsync(projectId); if (projectModel == null) { throw new UserFriendlyException((int)ErrorCode.DataAccessErr, "数据异常"); } var projectBase = await _projectBaseRepository.GetAsync(projectModel.ProjectId); if (projectBase == null) { throw new UserFriendlyException((int)ErrorCode.DataAccessErr, "数据异常"); } var data = new GetArchivesManagerForEditOutput(); var archivesModel = await _archivesManagerRepository.GetAll().FirstOrDefaultAsync(r => r.ProjectId == projectId); if (archivesModel == null) { data.Id = null; var files = from f in _projectFileRepository.GetAll() join filetype in _aappraisalFileTypeRepository.GetAll() on f.AappraisalFileType equals filetype.Id where f.ProjectBaseId == projectId select new { f.Id, f.FileName, f.FilePath, f.IsPaperFile, filetype.Name, f.PaperFileNumber }; data.ProjectId = projectModel.Id; data.ProjectName = projectModel.SingleProjectName; data.ProjectCode = projectModel.ProjectCode; data.SingleProjectCode = projectModel.SingleProjectCode; data.SingleProjectName = projectModel.SingleProjectName; data.AppraisalTypeId = projectBase.AppraisalTypeId; foreach (var file in files) { //if(string.IsNullOrWhiteSpace(file.FileName)) // continue; var entity = new CreateOrUpdateArchivesFileInput() { FileName = file.FileName, Id = file.Id, FileType = file.Name, IsPaper = file.IsPaperFile, PaperNumber = file.PaperFileNumber }; if (!string.IsNullOrWhiteSpace(file.FileName)) { entity.Files = Newtonsoft.Json.JsonConvert.DeserializeObject <List <FileUploadFiles> >(file.FileName); } data.Files.Add(entity); } } else { data.ArchivesName = archivesModel.ArchivesName; data.ArchivesNumber = archivesModel.ArchivesNumber; data.ArchivesNumber1 = archivesModel.ArchivesNumber1; data.ArchivesType = archivesModel.ArchivesType; data.Id = archivesModel.Id; data.Location = archivesModel.Location; data.PageNumber = archivesModel.PageNumber; data.ProjectCode = projectModel.ProjectCode; data.AppraisalTypeId = projectBase.AppraisalTypeId; data.ProjectId = projectId; data.ProjectName = projectModel.SingleProjectName; data.SingleProjectCode = projectModel.SingleProjectCode; data.SingleProjectName = projectModel.SingleProjectName; data.SecrecyLevel = archivesModel.SecrecyLevel; data.Summary = archivesModel.Summary; data.VolumeNumber = archivesModel.VolumeNumber; var files = from f in _archivesFileRepository.GetAll() where f.ArchivesId == archivesModel.Id select f; files.MapTo(data.Files); foreach (var filemodel in data.Files) { if (!string.IsNullOrWhiteSpace(filemodel.FileName)) { filemodel.Files = Newtonsoft.Json.JsonConvert.DeserializeObject <List <FileUploadFiles> >(filemodel.FileName); } } } return(data); }