public async Task <bool> Handle(CreateAgentVendorSpreadsheetCommand @command, CancellationToken cancellationToken) { var agent = await queryExecutor.Execute <GetAgentQuery, Agent>(new GetAgentQuery() { AgentId = @command.AggregateId }); var landlordSpreadsheet = CreateSpreadsheetForTrackingInquiry(agent, vendorInquiryHeaders, InquiryType.VendorLeads); agent.AgentSpreadsheet.VendorSpreadsheetUrl = landlordSpreadsheet.SpreadsheetUrl; agent.AgentSpreadsheet.VendorSpreadsheetId = landlordSpreadsheet.SpreadsheetId; agent.AgentSpreadsheet.VendorSpreadsheetName = agent.GetSpreadsheetName(Enum.GetName(typeof(InquiryType), InquiryType.VendorLeads)); var filter = Builders <Agent> .Filter.Eq("Id", agent.Id); var update = Builders <Agent> .Update .Set("AgentSpreadsheet", agent.AgentSpreadsheet) .CurrentDate("UpdatedDate"); await agentRepository.Collection .UpdateOneAsync(filter, update, new UpdateOptions { IsUpsert = true }); agent.CreateSpreadsheet(InquiryType.VendorLeads); await mediator.DispatchDomainEventsAsync(agent); return(true); }
public async Task <IActionResult> CreateAgentVendorSpreadsheet([FromBody] CreateAgentVendorSpreadsheetCommand @command) { var result = await mediator.Send(@command); return(result ? (IActionResult)Ok(result) : (IActionResult)BadRequest()); }