public async Task ApplyAsync(BaseWorkflow workflow) { if (!(workflow is RequestWorkflow)) { throw new ArgumentException( $"The argument type: ${workflow.GetType()} is not {nameof(RequestWorkflow)}"); } var requestWorkflow = (RequestWorkflow)workflow; requestWorkflow.DateUpdate = DateTimeOffset.Now; if (requestWorkflow.Id < 1) { requestWorkflow.DateCreate = DateTimeOffset.Now; } await _context.RequestWorkflows.AddAsync(requestWorkflow); var request = requestWorkflow.Owner ?? _context.Requests .Include(r => r.ProtectionDocType).Include(r => r.Documents) .ThenInclude(a => a.Document.Type).Include(r => r.CurrentWorkflow.CurrentStage) .SingleOrDefault(r => r.Id == requestWorkflow.OwnerId); if (request == null) { throw new ApplicationException($"Workflow has incorrect request id: {requestWorkflow.OwnerId}"); } var stage = await _context.DicRouteStages.SingleOrDefaultAsync(rs => rs.Id == requestWorkflow.CurrentStageId); CheckStage(request, stage); request.StatusId = stage?.RequestStatusId ?? request.StatusId; request.IsRead = false; request.CurrentWorkflow = requestWorkflow; request.CurrentWorkflowId = requestWorkflow.Id; request.DateUpdate = DateTimeOffset.Now; request.IsComplete = workflow.IsComplete ?? request.IsComplete; _context.Requests.Update(request); _context.SaveChanges(); await _taskRegister.RegisterAsync(request.Id); await _notificationSender.ProcessRequestAsync(request.Id); }
public async Task ApplyAsync(BaseWorkflow workflow) { if (!(workflow is ContractWorkflow)) { throw new ArgumentException($"The argument type: ${workflow.GetType()} is not {nameof(ContractWorkflow)}"); } var contractWorkflow = (ContractWorkflow)workflow; contractWorkflow.DateUpdate = DateTimeOffset.Now; if (contractWorkflow.Id < 1) { contractWorkflow.DateCreate = DateTimeOffset.Now; } await _context.ContractWorkflows.AddAsync(contractWorkflow); Domain.Entities.Contract.Contract contract = contractWorkflow.Owner ?? _context.Contracts.Single(c => c.Id == contractWorkflow.OwnerId); if (contract == null) { throw new ApplicationException($"Workflow has incorrect contract id: {contractWorkflow.OwnerId}"); } var stage = await _context.DicRouteStages.SingleOrDefaultAsync(rs => rs.Id == contractWorkflow.CurrentStageId); contract.CurrentWorkflow = contractWorkflow; contract.StatusId = stage?.ContractStatusId ?? contract.StatusId; contract.CurrentWorkflow = contractWorkflow; contract.CurrentWorkflowId = contractWorkflow.Id; contract.DateUpdate = DateTimeOffset.Now; contract.IsRead = false; contract.GosDate = stage != null && stage.Code.Equals("DK02.9.2") ? _calendarProvider.GetPublicationDate(contract.RegDate ?? contract.DateCreate) : contract.GosDate; _context.Contracts.Update(contract); await _context.SaveChangesAsync(); await _taskRegister.RegisterAsync(contract.Id); _notificationSender.ProcessContract(contract.Id); }
public async Task ApplyAsync(BaseWorkflow workflow) { if (!(workflow is DocumentWorkflow)) { throw new ArgumentException($"The argument type: ${workflow.GetType()} is not {nameof(DocumentWorkflow)}"); } var documentWorkflow = (DocumentWorkflow)workflow; var document = documentWorkflow.Owner ?? await _context.Documents.SingleOrDefaultAsync(d => d.Id == documentWorkflow.OwnerId); if (document == null) { throw new ApplicationException($"Workflow has incorrect document id: {documentWorkflow.OwnerId}"); } document.CurrentWorkflow = documentWorkflow; await _context.DocumentWorkflows.AddAsync(documentWorkflow); }
public async Task ApplyAsync(BaseWorkflow workflow) { if (!(workflow is ProtectionDocWorkflow)) { throw new ArgumentException( $"The argument type: ${workflow.GetType()} is not {nameof(ProtectionDocWorkflow)}"); } var protectionDocWorkflow = (ProtectionDocWorkflow)workflow; protectionDocWorkflow.DateUpdate = DateTimeOffset.Now; if (protectionDocWorkflow.Id < 1) { protectionDocWorkflow.DateCreate = DateTimeOffset.Now; } await _context.ProtectionDocWorkflows.AddAsync(protectionDocWorkflow); var protectionDoc = protectionDocWorkflow.Owner ?? _context.ProtectionDocs .Include(r => r.Type) .SingleOrDefault(r => r.Id == protectionDocWorkflow.OwnerId); if (protectionDoc == null) { throw new ApplicationException($"Workflow has incorrect request id: {protectionDocWorkflow.OwnerId}"); } var stage = await _context.DicRouteStages.SingleOrDefaultAsync(rs => rs.Id == protectionDocWorkflow.CurrentStageId); protectionDoc.StatusId = stage?.ProtectionDocStatusId ?? protectionDoc.StatusId; protectionDoc.CurrentWorkflow = protectionDocWorkflow; protectionDoc.CurrentWorkflowId = protectionDocWorkflow.Id; protectionDoc.DateUpdate = DateTimeOffset.Now; _context.ProtectionDocs.Update(protectionDoc); await _context.SaveChangesAsync(); await _notificationSender.ProcessRequestAsync(protectionDoc.Id); }