public async Task <EntityId> CreateVoucherAudit( [ActivityTrigger] IDurableActivityContext context, [DurableClient] IDurableEntityClient entityClient, ILogger log) { var request = context.GetInput <StartVAWorkflowRequest>(); var voucherAuditEntityId = new EntityId(nameof(VoucherAudit), request.VoucherAuditId.ToString()); var result = await entityClient.ReadEntityStateAsync <VoucherAudit>(voucherAuditEntityId); if (result.EntityExists) { throw new ApplicationException($"Workflow for VoucherAudit '{request.VoucherAuditId}' already started."); } var workflowBaseData = new WorkflowBaseData() { InstanceId = context.InstanceId, Auditors = request.Auditors, VoucherAuditId = request.VoucherAuditId }; await entityClient.SignalEntityAsync <IVoucherAudit>(voucherAuditEntityId, m => m.Start(workflowBaseData)); await entityClient.SignalEntityAsync <IVoucherAudit>(voucherAuditEntityId, m => m.SetStatus(VoucherAuditStatus.Started)); return(voucherAuditEntityId); }
public async Task <Workflow> Create(WorkflowBaseData workflowBaseData) { var workflow = new Workflow() { InstanceId = workflowBaseData.InstanceId, CreatedAt = DateTime.Now, Status = WorkflowStatus.Created.ToString(), Participants = workflowBaseData.Participants?.Select(m => new Participant() { Name = m, Status = ParticipantStatus.Waiting.ToString() }).ToList() }; var result = await _context.Workflows.AddAsync(workflow); await _context.SaveChangesAsync(); return(result.Entity); }
public void Start(WorkflowBaseData workflowBaseData) { VoucherAuditId = workflowBaseData.VoucherAuditId; Auditors = workflowBaseData.Auditors; InstanceId = workflowBaseData.InstanceId; }