public async Task ImportFromDb(string number, int requestId) { var refSqlQuey = string.Format(ImportSqlQueryHelper.ContractRefSqlQuery, string.Join(", ", ObjectType.GetRequestRouteIds()), string.Join(", ", ObjectType.GetContractRouteIds()), number); var oldRefContracts = await SqlDapperConnection.QueryAsync <RfMessageDocument>(refSqlQuey, TargetConnectionString); foreach (var oldRefContract in oldRefContracts) { var refContract = CreateRefContract(oldRefContract, requestId); if (refContract == null) { continue; } var oldContractId = refContract.ContractId; //Contract var newContractId = await FillContract(refContract.ContractId); if (newContractId == 0) { continue; } refContract.ContractId = newContractId; Executor.GetCommand <CreateContractRequestRelationsCommand>().Process(d => d.Execute(refContract)); refContract.DateCreate = new DateTimeOffset(oldRefContract.DateCreate.GetValueOrDefault(DateTime.Now)); Executor.GetCommand <UpdateContractRequestRelationsCommand>().Process(d => d.Execute(refContract)); //ContractWorkflow await FillContractWorkflows(oldContractId, newContractId); //ContractWorkflow await FillContractCustomers(oldContractId, newContractId); //attachments await FillAttachments(oldContractId, newContractId); try { //CurrentWorkflow var currentWorkflowSqlQuery = string.Format(ImportSqlQueryHelper.ContractsCurrentWorkflowSqlQuery, newContractId); await SqlDapperConnection.ExecuteAsync(currentWorkflowSqlQuery, SourceConnectionString); //MainAttachment var setMainAttachmentSqlQuery = string.Format(ImportSqlQueryHelper.SetContractsMainAttachmentSqlQuery, newContractId); await SqlDapperConnection.ExecuteAsync(setMainAttachmentSqlQuery, SourceConnectionString); } catch (Exception) { // ignored } //Documents await _importDocumentsHelper.ImportContractFromDb(oldContractId, newContractId); } }
private async Task FillContractCustomers(int oldContractId, int newContractId) { var customersSqlQuery = string.Format(ImportSqlQueryHelper.ContractCustomersSqlQuery, string.Join(", ", ObjectType.GetContractRouteIds()), oldContractId); var customers = await SqlDapperConnection.QueryAsync <RfCustomerAddressExtention>(customersSqlQuery, TargetConnectionString); foreach (var customer in customers) { var contractCustomer = await CreateCustomer(customer, newContractId); if (contractCustomer == null) { continue; } await Executor.GetCommand <CreateContractCustomerCommand>().Process(d => d.ExecuteAsync(contractCustomer)); contractCustomer.DateCreate = new DateTimeOffset(customer.DateCreate.GetValueOrDefault(DateTime.Now)); await Executor.GetCommand <UpdateContractCustomerCommand>().Process(d => d.ExecuteAsync(contractCustomer)); } }
private async Task <int> FillContract(int refContractId) { try { var sqlQuery = string.Format(ImportSqlQueryHelper.ContractSqlQuery, string.Join(", ", ObjectType.GetContractRouteIds()), refContractId); var oldContacts = await SqlDapperConnection.QueryAsync <DdDocument>(sqlQuery, TargetConnectionString); var ddContracts = oldContacts.ToList(); if (!ddContracts.Any()) { return(0); } var contract = await CreateContract(ddContracts.FirstOrDefault()); var newContractId = await Executor.GetCommand <CreateContractCommand>().Process(d => d.ExecuteFullObjAsync(contract)); contract.Id = newContractId; contract.DateCreate = new DateTimeOffset(ddContracts.First().DateCreate.GetValueOrDefault(DateTime.Now)); Executor.GetCommand <UpdateContractCommand>().Process(d => d.Execute(contract)); SavedContracts.Add(contract); return(newContractId); } catch (Exception) { return(0); } }
private async Task FillContractWorkflows(int oldContractId, int newContractId) { var wfSqlQuery = string.Format(ImportSqlQueryHelper.ContractsWfSqlQuery, string.Join(", ", ObjectType.GetContractRouteIds()), oldContractId); var oldWorkflows = await SqlDapperConnection.QueryAsync <WtPtWorkoffice>(wfSqlQuery, TargetConnectionString); foreach (var oldWorkflow in oldWorkflows) { var contractWorkflow = CreateWorkflow(oldWorkflow, newContractId); if (contractWorkflow == null) { continue; } await Executor.GetCommand <CreateContractWorkflowCommand>().Process(d => d.ExecuteAsync(contractWorkflow)); contractWorkflow.DateCreate = new DateTimeOffset(oldWorkflow.DateCreate.GetValueOrDefault(DateTime.Now)); Executor.GetCommand <UpdateContractWorkflowCommand>().Process(d => d.ExecuteAsync(contractWorkflow)); } }
public async Task ImportContractFromDb(int oldContractId, int newContractId) { TargetAttachmentConnectionString = Configuration.GetConnectionString("NiisDesctopAttachmentsConnection"); TargetConnectionString = Configuration.GetConnectionString("NiisDesctopConnection"); SourceConnectionString = Configuration.GetConnectionString("DefaultConnection"); var refSqlQuey = string.Format(ImportSqlQueryHelper.ContractDocRefSqlQuery, string.Join(", ", ObjectType.GetContractRouteIds()), string.Join(", ", ObjectType.GetMaterilsRouteIds()), oldContractId); var oldRefDocuments = await SqlDapperConnection.QueryAsync <RfMessageDocument>(refSqlQuey, TargetConnectionString); foreach (var oldRefDocument in oldRefDocuments) { var refDocument = CreateContractRefDocument(oldRefDocument, newContractId); if (refDocument == null) { continue; } var oldDocumentId = refDocument.DocumentId; //Document var newDocumentId = await FillDocument(refDocument.DocumentId); if (newDocumentId == 0) { continue; } refDocument.DocumentId = newDocumentId; Executor.GetCommand <CreateContractDocumentCommand>().Process(d => d.Execute(refDocument)); await FillDocRefs(oldDocumentId, newDocumentId); } }