public async Task <IActionResult> Get(int id) { var protectionDoc = await Executor.GetQuery <GetProtectionDocByIdQuery>().Process(q => q.ExecuteAsync(id)); if (protectionDoc.Workflows != null && protectionDoc.Workflows.Any(x => x.CurrentStage != null && x.CurrentStage.Code == RouteStageCodes.ODParallel) ) { ProtectionDocWorkflow userSpecificWorkflow = null; var userId = NiisAmbientContext.Current.User.Identity.UserId; if (Executor .GetQuery <TryGetProtectionDocWorkflowFromParalleByOwnerIdCommand>() .Process(q => q.Execute(protectionDoc.Id, userId, out userSpecificWorkflow)) && userSpecificWorkflow != null ) { protectionDoc.CurrentWorkflow = userSpecificWorkflow; protectionDoc.CurrentWorkflowId = userSpecificWorkflow.Id; } } var protectionDocDetailDto = Mapper.Map <ProtectionDoc, ProtectionDocDetailsDto>(protectionDoc); if (protectionDoc.Addressee != null) { protectionDocDetailDto.Addressee = Mapper.Map <SubjectDto>(protectionDoc.Addressee); } return(Ok(protectionDocDetailDto)); }
public async Task <IActionResult> SpecialUpdate(int id, [FromBody] KeyValuePair <string, object>[] specialValues) { await Executor.GetCommand <UpdateProtectionDocSpecialCommand>().Process(c => c.ExecuteAsync(id, specialValues)); var updatedProtectionDoc = await Executor.GetQuery <GetProtectionDocByIdQuery>().Process(q => q.ExecuteAsync(id)); if (updatedProtectionDoc.Workflows != null && updatedProtectionDoc.Workflows.Any(x => x.CurrentStage != null && x.CurrentStage.Code == RouteStageCodes.ODParallel) ) { ProtectionDocWorkflow userSpecificWorkflow = null; var userId = NiisAmbientContext.Current.User.Identity.UserId; if (Executor .GetQuery <TryGetProtectionDocWorkflowFromParalleByOwnerIdCommand>() .Process(q => q.Execute(updatedProtectionDoc.Id, userId, out userSpecificWorkflow)) && userSpecificWorkflow != null ) { updatedProtectionDoc.CurrentWorkflow = userSpecificWorkflow; updatedProtectionDoc.CurrentWorkflowId = userSpecificWorkflow.Id; } } var result = Mapper.Map <ProtectionDoc, ProtectionDocDetailsDto>(updatedProtectionDoc); return(Ok(result)); }
public bool Execute(int ownerId, int userId, out ProtectionDocWorkflow workflow) { var requestParallelWorkflowRepository = Uow.GetRepository <ProtectionDocParallelWorkflow>(); var parallelWorkflows = requestParallelWorkflowRepository.AsQueryable(); var requestProtectionDocWorkflow = Uow.GetRepository <ProtectionDocWorkflow>(); var appParallelWorkflowIds = parallelWorkflows .Where(x => x.OwnerId == ownerId && !x.IsFinished) .Select(x => x.ProtectionDocWorkflowId).ToArray(); workflow = requestProtectionDocWorkflow .AsQueryable() .Include(r => r.CurrentStage) .Include(cw => cw.FromStage) .Include(cw => cw.CurrentUser).ThenInclude(u => u.Department).ThenInclude(div => div.Division) .Where(x => appParallelWorkflowIds.Contains(x.Id)).FirstOrDefault(x => x.CurrentUserId.HasValue && x.CurrentUserId.Value == userId); if (workflow is null) { return(false); } return(true); }
public ProtectionDoc Execute(int requestId, int?specialUserId = null) { var repository = Uow.GetRepository <ProtectionDoc>(); var res = repository.AsQueryable() .Include(r => r.Type) .Include(r => r.CurrentWorkflow).ThenInclude(r => r.CurrentStage) .Include(r => r.CurrentWorkflow).ThenInclude(r => r.Route) .Select(d => new ProtectionDoc { CurrentWorkflow = new ProtectionDocWorkflow { Route = d.CurrentWorkflow.Route, CurrentStage = d.CurrentWorkflow.CurrentStage, DateCreate = d.CurrentWorkflow.DateCreate, Id = d.CurrentWorkflow.Id, ExternalId = d.CurrentWorkflow.ExternalId, DateUpdate = d.CurrentWorkflow.DateUpdate, ControlDate = d.CurrentWorkflow.ControlDate, CurrentStageId = d.CurrentWorkflow.CurrentStageId, CurrentUserId = d.CurrentWorkflow.CurrentUserId, DateReceived = d.CurrentWorkflow.DateReceived, Description = d.CurrentWorkflow.Description, FromStageId = d.CurrentWorkflow.FromStageId, FromUserId = d.CurrentWorkflow.FromUserId, OwnerId = d.CurrentWorkflow.OwnerId, PreviousWorkflowId = d.CurrentWorkflow.PreviousWorkflowId, RouteId = d.CurrentWorkflow.RouteId, IsComplete = d.CurrentWorkflow.IsComplete, IsMain = d.CurrentWorkflow.IsMain, IsSystem = d.CurrentWorkflow.IsSystem, SecondaryCurrentUserId = d.CurrentWorkflow.SecondaryCurrentUserId }, Type = new DicProtectionDocType { Code = d.Type.Code }, Id = d.Id }) .FirstOrDefault(r => r.Id == requestId); if (res.CurrentWorkflow != null && res.CurrentWorkflow.CurrentStage != null && res.CurrentWorkflow.CurrentStage.Code == RouteStageCodes.ODParallel) { var userId = specialUserId.HasValue ? specialUserId.Value : NiisAmbientContext.Current.User.Identity.UserId; ProtectionDocWorkflow parallelWorkflow = null; //var t = NiisAmbientContext.Current.Executor.GetQuery<TryGetProtectionDocWorkflowFromParalleByOwnerIdCommand>(); //var t1 = t.Process(q => q.Execute(requestId, userId, out parallelWorkflow)); if (NiisAmbientContext.Current.Executor.GetQuery <TryGetProtectionDocWorkflowFromParalleByOwnerIdCommand>().Process(q => q.Execute(requestId, userId, out parallelWorkflow)) && parallelWorkflow != null) { res.CurrentWorkflow = parallelWorkflow; NiisAmbientContext.Current.Executor.GetCommand <FinishProtectionDocParallelWorkflowCommand>().Process(q => q.Execute(parallelWorkflow)); } } return(res); }
public int Execute(ProtectionDocWorkflow protectionDoctWorkflow) { var requestWorkflowRepository = Uow.GetRepository <ProtectionDocWorkflow>(); requestWorkflowRepository.Create(protectionDoctWorkflow); Uow.SaveChanges(); return(protectionDoctWorkflow.Id); }
public async Task Handle(ProtectionDocWorkflow protectionDocWorkflow, Domain.Entities.ProtectionDoc.ProtectionDoc protectionDoc) { var routeStage = protectionDocWorkflow.CurrentStageId.HasValue ? Executor.GetQuery <GetDicRouteStageByIdQuery>().Process(q => q.Execute(protectionDocWorkflow.CurrentStageId.Value)) : null; protectionDoc.CurrentWorkflow = protectionDocWorkflow; protectionDoc.StatusId = routeStage?.ProtectionDocStatusId ?? protectionDoc.StatusId; await Executor.GetCommand <UpdateProtectionDocCommand>().Process(c => c.ExecuteAsync(protectionDoc.Id, protectionDoc)); }
public int Execute(ProtectionDocWorkflow protectionDoctWorkflow) { var requestParallelWorkflowRepository = Uow.GetRepository <ProtectionDocParallelWorkflow>(); var protectionDocParallelWorkflow = new ProtectionDocParallelWorkflow { IsFinished = false, OwnerId = protectionDoctWorkflow.OwnerId, ProtectionDocWorkflowId = protectionDoctWorkflow.Id }; requestParallelWorkflowRepository.Create(protectionDocParallelWorkflow); Uow.SaveChanges(); return(protectionDocParallelWorkflow.Id); }
public void Execute(ProtectionDocWorkflow protectionDoctWorkflow) { var requestParallelWorkflowRepository = Uow.GetRepository <ProtectionDocParallelWorkflow>(); var parallelWorkflows = requestParallelWorkflowRepository.AsQueryable(); var appParallelWorkflow = parallelWorkflows .FirstOrDefault(x => x.ProtectionDocWorkflowId == protectionDoctWorkflow.Id); if (appParallelWorkflow is null) { throw new DataNotFoundException(nameof(ProtectionDocParallelWorkflow), DataNotFoundException.OperationType.Read, "ProtectionDocWorkflowId"); } appParallelWorkflow.IsFinished = true; requestParallelWorkflowRepository.Update(appParallelWorkflow); Uow.SaveChanges(); }
public async Task <ProtectionDocWorkflow> ExecuteAsync(int protectionDocId, int userId) { var dicRouteStagesRepository = Uow.GetRepository <DicRouteStage>(); var initialStage = await dicRouteStagesRepository.AsQueryable().FirstOrDefaultAsync(s => s.IsFirst && s.RouteId == 22); if (initialStage == null) { return(null); } var protectionDocWorkflow = new ProtectionDocWorkflow { CurrentUserId = userId, OwnerId = protectionDocId, CurrentStageId = initialStage.Id, RouteId = initialStage.RouteId, IsComplete = initialStage.IsLast, IsSystem = initialStage.IsSystem, IsMain = initialStage.IsMain, }; return(protectionDocWorkflow); }
public void Process(ProtectionDocumentWorkFlowRequest protectionDocumentWorkFlowRequest, int?specialUserId = null) { var current = NiisAmbientContext.Current; ProtectionDocWorkflow specWorkf = null; if (current != null && current.User != null && current.User.Identity != null) { specialUserId = NiisAmbientContext.Current.User.Identity.UserId; } if (specialUserId.HasValue && !_executor .GetQuery <TryGetProtectionDocWorkflowFromParalleByOwnerIdCommand>() .Process(r => r.Execute(protectionDocumentWorkFlowRequest.ProtectionDocId, specialUserId.Value, out specWorkf)) || specWorkf != null && new string[] { RouteStageCodes.OD03_1, RouteStageCodes.OD01_6 }.Contains(specWorkf.CurrentStage.Code) ) { if (protectionDocumentWorkFlowRequest.ProtectionDocId != 0) { protectionDocumentWorkFlowRequest.CurrentWorkflowObject = _executor .GetQuery <GetProtectionDocByIdForWorkflowServiceQuery>().Process(r => r.Execute(protectionDocumentWorkFlowRequest.ProtectionDocId, specialUserId)); if (protectionDocumentWorkFlowRequest.IsAuto) { protectionDocumentWorkFlowRequest.NextStageUserId = protectionDocumentWorkFlowRequest?.CurrentWorkflowObject?.CurrentWorkflow?.CurrentUserId ?? 0; } RequestWorkflows(protectionDocumentWorkFlowRequest); } } }
public async Task <object> Handle(Command message) { foreach (var id in message.Ids) { var protectionDoc = _context.ProtectionDocs .Include(pd => pd.CurrentWorkflow) .Single(pd => pd.Id == id); var nextStage = _context.DicRouteStages.Single(rs => rs.Code.Equals("OD01.3")); var nextWorkflow = new ProtectionDocWorkflow { OwnerId = protectionDoc.Id, FromUserId = protectionDoc.CurrentWorkflow.CurrentUserId, FromStageId = protectionDoc.CurrentWorkflow.CurrentStageId, CurrentUserId = message.UserId, CurrentStageId = nextStage.Id, RouteId = nextStage.RouteId, IsComplete = nextStage.IsLast, IsSystem = nextStage.IsSystem, IsMain = nextStage.IsMain }; await _workflowApplier.ApplyAsync(nextWorkflow); } return(null); }
public async Task <int> ExecuteAsync(int ownerId, Owner.Type ownerType, string documentTypeCode, DocumentType type, UserInputDto userInputDto, int?specialUserId = null) { var documentType = Executor.GetQuery <GetDicDocumentTypeByCodeQuery>() .Process(q => q.Execute(documentTypeCode ?? string.Empty)); if (documentType == null) { throw new DataNotFoundException(nameof(DicDocumentType), DataNotFoundException.OperationType.Read, documentTypeCode); } int?currentUserId; int?addresseeId; switch (ownerType) { case Owner.Type.Request: var request = await Executor.GetQuery <GetRequestByIdQuery>().Process(q => q.ExecuteAsync(ownerId)); if (request == null) { throw new DataNotFoundException(nameof(Request), DataNotFoundException.OperationType.Read, ownerId); } addresseeId = request.RequestCustomers.FirstOrDefault(c => c.CustomerRole.Code == DicCustomerRoleCodes.Correspondence)?.CustomerId; currentUserId = request.CurrentWorkflow.CurrentUserId; break; case Owner.Type.ProtectionDoc: var protectionDoc = await Executor.GetQuery <GetProtectionDocByIdQuery>() .Process(q => q.ExecuteAsync(ownerId)); if (protectionDoc == null) { throw new DataNotFoundException(nameof(ProtectionDoc), DataNotFoundException.OperationType.Read, ownerId); } addresseeId = protectionDoc.ProtectionDocCustomers.FirstOrDefault(c => c.CustomerRole.Code == DicCustomerRoleCodes.Correspondence)?.CustomerId; ProtectionDocWorkflow userSpecificWorkflow = null; if (specialUserId.HasValue && Executor .GetQuery <TryGetProtectionDocWorkflowFromParalleByOwnerIdCommand>() .Process(q => q.Execute(protectionDoc.Id, specialUserId.Value, out userSpecificWorkflow)) && userSpecificWorkflow != null) { currentUserId = userSpecificWorkflow.CurrentUserId; } else { currentUserId = protectionDoc.CurrentWorkflow.CurrentUserId; } break; case Owner.Type.Contract: var contract = await Executor.GetQuery <GetContractByIdQuery>().Process(q => q.ExecuteAsync(ownerId)); if (contract == null) { throw new DataNotFoundException(nameof(Contract), DataNotFoundException.OperationType.Read, ownerId); } addresseeId = contract.ContractCustomers.FirstOrDefault(c => c.CustomerRole.Code == DicCustomerRoleCodes.Correspondence)?.CustomerId; currentUserId = contract.CurrentWorkflow.CurrentUserId; break; default: throw new NotImplementedException(); } var document = new Document { TypeId = documentType.Id, AddresseeId = addresseeId, DocumentType = type, DateCreate = DateTimeOffset.Now }; var documentId = await Executor.GetCommand <CreateDocumentCommand>().Process(c => c.ExecuteAsync(document)); switch (ownerType) { case Owner.Type.Request: await Executor.GetCommand <AddRequestDocumentsCommand>().Process(c => c.ExecuteAsync(new List <RequestDocument> { new RequestDocument { RequestId = ownerId, DocumentId = documentId } })); break; case Owner.Type.ProtectionDoc: await Executor.GetCommand <AddProtectionDocDocumentsCommand>().Process(c => c.ExecuteAsync(new List <ProtectionDocDocument> { new ProtectionDocDocument { ProtectionDocId = ownerId, DocumentId = documentId } })); break; case Owner.Type.Contract: await Executor.GetCommand <AddContractDocumentsCommand>().Process(c => c.ExecuteAsync(new List <ContractDocument> { new ContractDocument { ContractId = ownerId, DocumentId = documentId } })); break; default: throw new NotImplementedException(); } var documentWorkflow = await Executor.GetQuery <GetInitialDocumentWorkflowQuery>().Process(q => q.ExecuteAsync(documentId, currentUserId ?? throw new DataNotFoundException(nameof(DicCustomer), DataNotFoundException.OperationType.Read, 0))); await Executor.GetCommand <ApplyDocumentWorkflowCommand>().Process(c => c.ExecuteAsync(documentWorkflow)); await Executor.GetCommand <UpdateDocumentCommand>().Process(c => c.Execute(document)); await Executor.GetHandler <GenerateDocumentBarcodeHandler>().Process(c => c.ExecuteAsync(documentId)); await Executor.GetHandler <GenerateRegisterDocumentNumberHandler>().Process(c => c.ExecuteAsync(documentId)); await Executor.GetCommand <CreateUserInputCommand>().Process(c => c.ExecuteAsync(documentId, userInputDto)); await Executor.GetHandler <ProcessWorkflowByDocumentIdHandler>().Process(r => r.ExecuteAsync(documentId, specialUserId)); return(documentId); }
/// <summary> /// Создание Охранного документа(ОД) /// </summary> private void GenerateProtectionDocument(RequestWorkFlowRequest workflowRequest) { var request = Executor.GetQuery <GetRequestByIdQuery>().Process(r => r.Execute(workflowRequest.RequestId)); var dicProtectionDocStatus = Executor.GetQuery <GetDicProtectionDocStatusByCodeQuery>().Process(r => r.Execute(DicProtectionDocStatusCodes.D)); var defaultSendType = Executor.GetQuery <GetSendTypeByCodeQuery>() .Process(q => q.Execute(DicSendTypeCodes.ByHand)); if (dicProtectionDocStatus == null) { return; } //int addYears = 0; string protectionDocTypeCode = ""; switch (request?.ProtectionDocType?.Code) { case DicProtectionDocTypeCodes.RequestTypeTrademarkCode: //addYears = 10; protectionDocTypeCode = DicProtectionDocTypeCodes.ProtectionDocTypeTrademarkCode; break; case DicProtectionDocTypeCodes.RequestTypeNameOfOriginCode: protectionDocTypeCode = DicProtectionDocTypeCodes.ProtectionDocTypeNameOfOriginCode; //addYears = 10; break; case DicProtectionDocTypeCodes.RequestTypeSelectionAchieveCode: protectionDocTypeCode = DicProtectionDocTypeCodes.ProtectionDocTypeSelectionAchieveCode; switch (request.SelectionAchieveType.Code) { case DicSelectionAchieveTypeCodes.Agricultural: //addYears = 25; break; case DicSelectionAchieveTypeCodes.AnimalHusbandry: //addYears = 30; break; case DicSelectionAchieveTypeCodes.VarietiesPlant: //addYears = 35; break; } break; case DicProtectionDocTypeCodes.RequestTypeUsefulModelCode: protectionDocTypeCode = DicProtectionDocTypeCodes.ProtectionDocTypeUsefulModelCode; //addYears = 5; break; case DicProtectionDocTypeCodes.RequestTypeInventionCode: protectionDocTypeCode = DicProtectionDocTypeCodes.ProtectionDocTypeInventionCode; //addYears = 20; break; case DicProtectionDocTypeCodes.RequestTypeIndustrialSampleCode: protectionDocTypeCode = DicProtectionDocTypeCodes.ProtectionDocTypeIndustrialSampleCode; //addYears = 15; break; } //var validDate = request?.RequestDate?.AddYears(addYears); var protectionDocType = Executor.GetQuery <GetDicProtectionDocTypebyCodeQuery>() .Process(q => q.Execute(protectionDocTypeCode)); //todo вынести новые коды в класс var protectionDocSubtype = Executor.GetQuery <GetDicProtectionDocSubTypeByCodeQuery>() .Process(q => q.Execute(request?.RequestType?.Code + "_PD")); //Создаем ОД var protectionDocument = new ProtectionDoc { TypeId = protectionDocType?.Id ?? 0, SubTypeId = protectionDocSubtype?.Id ?? 0, StatusId = dicProtectionDocStatus.Id, SelectionAchieveTypeId = request?.SelectionAchieveTypeId, ConventionTypeId = request?.ConventionTypeId, BeneficiaryTypeId = request?.BeneficiaryTypeId, TypeTrademarkId = request?.TypeTrademarkId, RegNumber = request?.RequestNum, RegDate = request?.RequestDate, GosDate = NiisAmbientContext.Current.DateTimeProvider.Now, //ЦValidDate = validDate, Referat = request?.Referat, NameRu = request?.NameRu, NameKz = request?.NameKz, NameEn = request?.NameEn, SelectionFamily = request?.SelectionFamily, Image = request?.Image, PreviewImage = request?.PreviewImage, IsImageFromName = request?.IsImageFromName ?? false, DisclaimerRu = request?.DisclaimerRu, DisclaimerKz = request?.DisclaimerKz, RequestId = workflowRequest.RequestId, AddresseeId = request?.AddresseeId, SendTypeId = defaultSendType?.Id }; Executor.GetHandler <GenerateBarcodeHandler>().Process <object>(h => h.Execute(protectionDocument)); Executor.GetCommand <CreateProtectionDocCommand>().Process(r => r.Execute(protectionDocument)); var requestProtectionDocSimilar = new RequestProtectionDocSimilar { RequestId = workflowRequest.RequestId, ProtectionDocId = protectionDocument.Id, DateCreate = DateTimeOffset.Now }; Executor.GetCommand <CreateRequestProtectionDocSimilarCommand>().Process(r => r.Execute(requestProtectionDocSimilar)); string initialStageCode; if (protectionDocType.Code == DicProtectionDocTypeCodes.ProtectionDocTypeNameOfOriginCode) { initialStageCode = RouteStageCodes.PD_NMPT_AssignmentRegistrationNumber; } else if (protectionDocType.Code == DicProtectionDocTypeCodes.ProtectionDocTypeTrademarkCode) { initialStageCode = RouteStageCodes.PD_TM_AssignmentRegistrationNumber; } else { initialStageCode = RouteStageCodes.OD01_1; } var initialStage = Executor.GetQuery <GetDicRouteStageByCodeQuery>().Process(r => r.Execute(initialStageCode)); var protectionDocWorkflow = new ProtectionDocWorkflow { CurrentUserId = workflowRequest.NextStageUserId, OwnerId = protectionDocument.Id, CurrentStageId = initialStage.Id, RouteId = initialStage.RouteId, IsComplete = initialStage.IsLast, IsSystem = initialStage.IsSystem, IsMain = initialStage.IsMain, }; //Создали этап Executor.GetCommand <CreateProtectionDocWorkflowCommand>().Process(r => r.Execute(protectionDocWorkflow)); //Добавили и обновили текущий этап у ОД protectionDocument.CurrentWorkflowId = protectionDocWorkflow.Id; Executor.GetCommand <UpdateProtectionDocCommand>().Process(r => r.Execute(protectionDocument)); //Платежи заявки теперь относятся и к ОД (новое требование: не наследовать платежи) Executor.GetCommand <UpdateRequestPaymentInvoicesByProtectionDocIdCommand>().Process(r => r.Execute(request.Id, protectionDocument.Id)); #region Перенос биб. данных var mapper = NiisAmbientContext.Current.Mapper; var protectionDocId = protectionDocument.Id; var requestId = request.Id; //TODO: реализовать перенос TODO! тянуть только то, что нужно в зависимости от типа ОД var requestConventionInfos = Executor.GetQuery <GetConventionInfosByRequestIdQuery>().Process(q => q.Execute(requestId)); var protectionDocConventionInfos = mapper.Map <List <RequestConventionInfo>, List <ProtectionDocConventionInfo> >(requestConventionInfos); Executor.GetCommand <AddProtectionDocConventionInfosRangeCommand>().Process(c => c.Execute(protectionDocId, protectionDocConventionInfos)); var requestEarlyRegs = Executor.GetQuery <GetEarlyRegsByRequestIdQuery>().Process(q => q.Execute(requestId)); var protectionDocEarlyRegs = mapper.Map <List <RequestEarlyReg>, List <ProtectionDocEarlyReg> >(requestEarlyRegs); Executor.GetCommand <AddProtectionDocEarlyRegsRangeCommand>().Process(c => c.Execute(protectionDocId, protectionDocEarlyRegs)); var icgsRequests = Executor.GetQuery <GetIcgsByRequestIdQuery>().Process(q => q.Execute(requestId)); var icgsProtectionDocs = mapper.Map <List <ICGSRequest>, List <ICGSProtectionDoc> >(icgsRequests); Executor.GetCommand <AddIcgsProtectionDocRangeCommand>().Process(c => c.Execute(protectionDocId, icgsProtectionDocs)); var icisRequests = Executor.GetQuery <GetIcisByRequestIdQuery>().Process(q => q.Execute(requestId)); var icisProtectionDocs = mapper.Map <List <ICISRequest>, List <ICISProtectionDoc> >(icisRequests); Executor.GetCommand <AddIcisProtectionDocRelationsCommand>().Process(c => c.Execute(protectionDocId, icisProtectionDocs.Select(icis => icis.IcisId).ToList())); var ipcRequests = Executor.GetQuery <GetIpcByRequestIdQuery>().Process(q => q.Execute(requestId)); Executor.GetCommand <AddIpcProtectionDocRelationsCommand>().Process(c => c.Execute(protectionDocId, ipcRequests.ToList())); var requestColorTzs = Executor.GetQuery <GetColorTzsByRequestIdQuery>().Process(q => q.Execute(requestId)); var colorTzIds = requestColorTzs.Select(color => color.ColorTzId).ToList(); Executor.GetCommand <AddColorTzProtectionDocRelationsCommand>().Process(c => c.Execute(protectionDocId, colorTzIds)); var icfemRequests = Executor.GetQuery <GetIcfemByRequestIdQuery>().Process(q => q.Execute(requestId)); var icfemProtectionDocs = mapper.Map <List <DicIcfemRequestRelation>, List <DicIcfemProtectionDocRelation> >(icfemRequests); Executor.GetCommand <AddIcfemProtectionDocRelationsCommand>().Process(c => c.Execute(protectionDocId, icfemProtectionDocs.Select(icfem => icfem.DicIcfemId).ToList())); var protectionDocInfo = mapper.Map <RequestInfo, ProtectionDocInfo>(request.RequestInfo); Executor.GetCommand <CreateProtectionDocInfoCommand>().Process(c => c.Execute(protectionDocId, protectionDocInfo)); #endregion var protectionDocCustomers = mapper.Map <List <RequestCustomer>, List <ProtectionDocCustomer> >(request.RequestCustomers.ToList()); Executor.GetCommand <AddProtectionDocCustomersCommand>().Process(c => c.Execute(protectionDocId, protectionDocCustomers)); }
public async Task <IActionResult> SplitProtectionDoc(int id, [FromBody] IcgsDto[] icgsDtos) { var protectionDoc = await Executor.GetQuery <GetProtectionDocByIdQuery>().Process(q => q.ExecuteAsync(id)); var newProtectionDoc = Mapper.Map <ProtectionDoc>(protectionDoc); #region Создание охранного документа newProtectionDoc.TypeId = protectionDoc.TypeId; newProtectionDoc.SubTypeId = protectionDoc.SubTypeId; newProtectionDoc.DateCreate = DateTimeOffset.Now; newProtectionDoc.RequestId = protectionDoc.RequestId; newProtectionDoc.Transliteration = protectionDoc.Transliteration; await Executor.GetHandler <GenerateNumberForSplitProtectionDocsHandler>().Process(h => h.ExecuteAsync(protectionDoc, newProtectionDoc)); Executor.GetHandler <GenerateBarcodeHandler>().Process(h => h.Execute(newProtectionDoc)); var newProtectionDocId = await Executor.GetCommand <CreateProtectionDocCommand>().Process(c => c.ExecuteAsync(newProtectionDoc)); if (newProtectionDoc.RequestId != null) { //Создаем связь между заявкой и охранным документом. var requestProtectionDocSimilar = new RequestProtectionDocSimilar { RequestId = (int)newProtectionDoc.RequestId, ProtectionDocId = newProtectionDoc.Id, DateCreate = DateTimeOffset.Now }; Executor.GetCommand <CreateRequestProtectionDocSimilarCommand>().Process(r => r.Execute(requestProtectionDocSimilar)); } var newWorkflows = Mapper.Map <ProtectionDocWorkflow[]>(protectionDoc.Workflows).OrderBy(w => w.DateCreate); foreach (var newWorkflow in newWorkflows) { newWorkflow.OwnerId = newProtectionDocId; Executor.GetCommand <CreateProtectionDocWorkflowCommand>().Process(c => c.Execute(newWorkflow)); } var initialStage = await Executor.GetQuery <GetDicRouteStageByCodeQuery>().Process(q => q.ExecuteAsync(protectionDoc.CurrentWorkflow.FromStage.Code)); var initialWorkflow = new ProtectionDocWorkflow() { CurrentUserId = NiisAmbientContext.Current.User.Identity.UserId, OwnerId = newProtectionDocId, CurrentStageId = initialStage.Id, RouteId = initialStage.RouteId, IsComplete = initialStage.IsLast, IsSystem = initialStage.IsSystem, IsMain = initialStage.IsMain, }; var initialWorkflowId = Executor.GetCommand <CreateProtectionDocWorkflowCommand>().Process(c => c.Execute(initialWorkflow)); newProtectionDoc.CurrentWorkflowId = initialWorkflowId; await Executor.GetCommand <UpdateProtectionDocCommand>().Process(c => c.ExecuteAsync(newProtectionDocId, newProtectionDoc)); #endregion await CreatePatentOrCertificate(newProtectionDocId, null); #region МКТУ var newIcgsProtectionDocs = Mapper.Map <ICGSProtectionDoc[]>(icgsDtos); foreach (var newIcgsRequest in newIcgsProtectionDocs) { newIcgsRequest.ProtectionDocId = newProtectionDocId; } await Executor.GetCommand <UpdateIcgsProtectionDocRangeCommand>() .Process(c => c.ExecuteAsync(id, newIcgsProtectionDocs.ToList())); #endregion #region Биб. данные var newConventionInfos = Mapper.Map <ProtectionDocConventionInfo[]>(protectionDoc.ProtectionDocConventionInfos); await Executor.GetCommand <AddProtectionDocConventionInfosRangeCommand>() .Process(c => c.ExecuteAsync(newProtectionDocId, newConventionInfos.ToList())); var newProtectionDocEarlyRegs = Mapper.Map <ProtectionDocEarlyReg[]>(protectionDoc.EarlyRegs); await Executor.GetCommand <AddProtectionDocEarlyRegsRangeCommand>() .Process(c => c.ExecuteAsync(newProtectionDocId, newProtectionDocEarlyRegs.ToList())); var newIpcProtectionDocs = Mapper.Map <IPCProtectionDoc[]>(protectionDoc.IpcProtectionDocs); await Executor.GetCommand <AddIpcProtectionDocRelationsCommand>().Process(c => c.ExecuteAsync(newProtectionDocId, newIpcProtectionDocs.Select(i => i.IpcId).ToList())); var newIcisProtectionDocs = Mapper.Map <ICISProtectionDoc[]>(protectionDoc.IcisProtectionDocs); await Executor.GetCommand <AddIcisProtectionDocRelationsCommand>().Process(c => c.ExecuteAsync(newProtectionDocId, newIcisProtectionDocs.Select(i => i.IcisId).ToList())); await Executor.GetCommand <AddColorTzProtectionDocRelationsCommand>().Process(c => c.ExecuteAsync(newProtectionDocId, protectionDoc.ColorTzs.Select(color => color.ColorTzId).ToList())); await Executor.GetCommand <AddIcfemProtectionDocRelationsCommand>().Process(c => c.ExecuteAsync(newProtectionDocId, protectionDoc.Icfems.Select(i => i.DicIcfemId).ToList())); #endregion #region Контрагенты var newCustomers = Mapper.Map <ProtectionDocCustomer[]>(protectionDoc.ProtectionDocCustomers); await Executor.GetCommand <AddProtectionDocCustomersCommand>().Process(c => c.ExecuteAsync(newProtectionDocId, newCustomers.ToList())); #endregion var protectionDocumentWorkFlowRequest = new ProtectionDocumentWorkFlowRequest() { ProtectionDocId = id, NextStageUserId = protectionDoc.CurrentWorkflow?.FromUserId ?? 0, NextStageCode = protectionDoc.CurrentWorkflow?.FromStage.Code ?? "", }; NiisWorkflowAmbientContext.Current.ProtectionDocumentWorkflowService.Process(protectionDocumentWorkFlowRequest); return(Ok(newProtectionDocId)); }