public async Task CreateOrUpdateArchivesManager(CreateOrUpdateArchivesManagerInput input) { if (input.Id.HasValue) { await UpdateArchivesManagerAsync(input); } else { await CreateArchivesManagerAsync(input); } }
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); }
protected virtual async Task UpdateArchivesManagerAsync(CreateOrUpdateArchivesManagerInput input) { var model = await _archivesManagerRepository.GetAsync(input.Id.Value); if (model == null) { throw new UserFriendlyException((int)ErrorCode.DataAccessErr, "数据异常"); } var old_Model = model.DeepClone(); var filedbModel = await _archivesFileRepository.GetAll().Where(r => r.ArchivesId == model.Id).ToListAsync(); var add_fileModel = input.Files.Where(r => r.Id == null).ToList(); add_fileModel.ForEach(r => { r.ArchivesId = model.Id; _archivesFileRepository.InsertAsync(r.MapTo <ArchivesFile>()); }); var less_fileControlIds = filedbModel.Select(r => r.Id).ToList().Except(input.Files.Where(r => r.Id.HasValue).Select(o => o.Id.Value).ToList()).ToList(); less_fileControlIds.ForEach(r => { _archivesFileRepository.Delete(filedbModel.FirstOrDefault(o => o.Id == r)); }); var update_files = input.Files.Where(r => r.Id != null && !less_fileControlIds.Contains(r.Id.Value)).ToList(); update_files.ForEach(r => { var db_file = filedbModel.FirstOrDefault(o => o.Id == r.Id.Value); r.MapTo(db_file); _archivesFileRepository.UpdateAsync(db_file); }); input.MapTo(model); await _archivesManagerRepository.UpdateAsync(model); await CurrentUnitOfWork.SaveChangesAsync(); if (input.IsUpdateForChange) { var flowModel = _workFlowCacheManager.GetWorkFlowModelFromCache(input.FlowId); if (flowModel == null) { throw new UserFriendlyException((int)ErrorCode.DataAccessErr, "流程不存在"); } var logs = GetChangeModel(old_Model).GetColumnAllLogs(GetChangeModel(model)); await _projectAuditManager.InsertAsync(logs, input.Id.ToString(), flowModel.TitleField.Table); } }
protected virtual async Task CreateArchivesManagerAsync(CreateOrUpdateArchivesManagerInput input) { var archivesManager = new ArchivesManager(); input.MapTo(archivesManager); var id = Guid.NewGuid(); archivesManager.Id = id; await _archivesManagerRepository.InsertAsync(archivesManager); foreach (var file in input.Files) { var entity = new ArchivesFile(); file.Id = Guid.NewGuid(); file.ArchivesId = id; file.MapTo(entity); await _archivesFileRepository.InsertAsync(entity); } await CurrentUnitOfWork.SaveChangesAsync(); }