Exemple #1
0
        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);
            }
        }
Exemple #2
0
        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();
        }