internal void SaveContract(Contract contract) { _context.Contracts.Add(contract); _context.SaveChanges(); contract.CurrentWorkflowId = contract.Workflows?.OrderByDescending(r => r.DateCreate).FirstOrDefault()?.Id; _context.SaveChanges(); }
public void AttachFilesToDocuments(List <Document> documents, NiisWebContextMigration niisWebContext, ref int migratedFilesCount) { var documentFiles = _oldNiisDocumentDataService.GetDdDocumentDatas(documents.Select(r => r.Barcode).ToList()); if (documentFiles.Any() == false) { return; } foreach (var document in documents) { var documentData = documentFiles.SingleOrDefault(d => d.Id == document.Barcode); if (documentData == null) { continue; } if (documentData.FileName == null) { return; } var validFileName = $"{document.Barcode}.{Path.GetExtension(documentData.FileName)}"; var attachment = new Attachment { DocumentId = document.Id, AuthorId = _appConfiguration.AuthorAttachmentDocumentId, ContentType = FileTypeHelper.GetContentType(documentData.FileName), BucketName = $"old-document-{document.Barcode}", IsMain = true, DateCreate = documentData.DateCreate, DateUpdate = documentData.DateUpdate, OriginalName = documentData.FileName, Length = documentData.File.Length, ValidName = validFileName, Hash = _generateHash.GenerateFileHash(documentData.File) }; niisWebContext.Attachments.Add(attachment); niisWebContext.SaveChanges(); _fileStorage.AddAsync(attachment.BucketName, attachment.ValidName, documentData.File, attachment.ContentType).Wait(); document.MainAttachmentId = attachment.Id; niisWebContext.SaveChanges(); migratedFilesCount++; } }
public void MigrateContractAttachments() { int lastContractId = 0; MigratedFilesCount = 0; using (_context = new NiisWebContextMigration(OptionsBuilder.Options)) { lastContractId = _context.Contracts.OrderByDescending(r => r.Id).First().Id; } while (lastContractId > LastMigratedContractId) { using (var _context = new NiisWebContextMigration(OptionsBuilder.Options)) { var contracts = _context.Contracts .Where(r => r.Id > LastMigratedContractId && r.MainAttachmentId.HasValue == false) .OrderBy(r => r.Id) .Take(_appConfiguration.PackageSizeForFile) .ToList(); if (contracts.Any() == false) { break; } foreach (var contract in contracts) { try { var mainAttachmentId = _attachmentFileHelper.GetMainAttachmentId(contract.Id, _context); if (mainAttachmentId.HasValue == true) { contract.MainAttachmentId = mainAttachmentId; _context.SaveChanges(); MigratedFilesCount++; } File.WriteAllText(ContractDataFilePath, contracts.Last().Id.ToString()); } catch (Exception ex) { var logErrorText = $"Ошибка при загрузки файла для договоров с Id: {contract.Id}. текст ошибки" + ex.Message; Log.LogError(logErrorText); Console.WriteLine(logErrorText); if (ex.InnerException != null) { Console.WriteLine(ex.InnerException); } } } Console.Write($"\rМигрировано {MigratedFilesCount} файлов. Затрачено времени: {StopwatchRequestFiels.Elapsed}"); } } }
public void AttachFilesToRequests(List <Request> requests, NiisWebContextMigration niisWebContext, ref int migratedFilesCount) { var documentFiles = _oldNiisDocumentDataService.GetDdDocumentDatas(requests.Select(r => r.Barcode).ToList()); if (documentFiles.Any() == false) { return; } foreach (var request in requests) { var documentData = documentFiles.SingleOrDefault(d => d.Id == request.Barcode); if (documentData == null) { continue; } if (string.IsNullOrWhiteSpace(documentData.FileName)) { documentData.FileName = $"{request.Barcode}.{FileTypes.Pdf}"; } var attachment = new Attachment { AuthorId = request.UserId ?? _appConfiguration.AuthorAttachmentDocumentId, ContentType = FileTypeHelper.GetContentType(documentData.FileName), BucketName = $"old-request-{request.Barcode}", IsMain = true, CopyCount = request.CopyCount, PageCount = request.PageCount, DateCreate = documentData.DateCreate, DateUpdate = documentData.DateUpdate, OriginalName = documentData.FileName, Length = documentData.File.Length, ValidName = documentData.FileName.MakeValidFileName(), Hash = _generateHash.GenerateFileHash(documentData.File) }; _newNiisAttachmentFileService = new NewNiisAttachmentFileService(niisWebContext); _newNiisAttachmentFileService.CreateAttachment(attachment); _fileStorage.AddAsync(attachment.BucketName, attachment.ValidName, documentData.File, attachment.ContentType).Wait(); request.MainAttachmentId = attachment.Id; niisWebContext.SaveChanges(); migratedFilesCount++; } }
public void CreateRangeProtectionDocs(List <ProtectionDoc> protectionDocs) { _context.ProtectionDocs.AddRange(protectionDocs); _context.SaveChanges(); }
public void CreateRangePayments(IEnumerable <object> payments) { _context.AddRange(payments); _context.SaveChanges(); }
public void CreateRangeDocumentEarlyRegs(List <DocumentEarlyReg> documentEarlyReg) { _context.DocumentEarlyRegs.AddRange(documentEarlyReg); _context.SaveChanges(); }
public void CreateRangeRequests(List <Request> requests) { _context.Requests.AddRange(requests); _context.SaveChanges(); }
public void CreateRangeDocuments(List <Document> documents) { _context.Documents.AddRange(documents); _context.SaveChanges(); }
public void CreateRangeSecurityUsers(IEnumerable <object> securityUsers, Type entityType) { _context.AddRange(securityUsers); _context.SaveChanges(); }
public void CreateRangeDicColorTZRequests(List <DicColorTZRequestRelation> colorsRequests) { _context.DicColorTzRequestRelations.AddRange(colorsRequests); _context.SaveChanges(); }
public void CreateRangeDictionaries(IEnumerable <object> dictionaries) { _context.AddRange(dictionaries); _context.SaveChanges(); }
public void CreateRangeMainEntityRelations(IEnumerable <object> mainEntityRelations) { _context.AddRange(mainEntityRelations); _context.SaveChanges(); }
public void CreateAttachment(Attachment attachment) { _context.Attachments.Add(attachment); _context.SaveChanges(); }
public void CreateRangeProtectionDocRelations(IEnumerable <object> protectionDocRelations) { _context.AddRange(protectionDocRelations); _context.SaveChanges(); }