public async Task <bool> Handle(CreateAgentTypeFormAccountForRentInquiryCommand @command, CancellationToken cancellationToken)
        {
            var agent = await queryExecutor.Execute <GetAgentQuery, Agent>(new GetAgentQuery()
            {
                AgentId = @command.AggregateId
            });

            var rentInquiryTemplateUrl = configuration.GetValue <string>("TypeFormRentInquiryTemplateUrl");

            string typeFormTemplateJson = await typeForm.GetTypeFormAsync(rentInquiryTemplateUrl);

            var typeFormUrl = await CreateTypeFormUrl(agent, InquiryType.RentInquiry, typeFormTemplateJson);

            if (agent.RentInquiry == null)
            {
                agent.RentInquiry = new AgentRentInquiry();
            }

            agent.RentInquiry.UpdateTypeform(typeFormUrl);

            var filter = Builders <Agent> .Filter.Eq("Id", agent.Id);

            var update = Builders <Agent> .Update
                         .Set("RentInquiry", agent.RentInquiry)
                         .CurrentDate("UpdatedDate");

            await agentRepository.Collection
            .UpdateOneAsync(filter, update, new UpdateOptions { IsUpsert = true });

            agent.CreateTypeform(InquiryType.RentInquiry);
            await mediator.DispatchDomainEventsAsync(agent);

            return(true);
        }
Example #2
0
        public async Task <IActionResult> CreateAgentTypeFormAccountForRentInquiryCommand([FromBody] CreateAgentTypeFormAccountForRentInquiryCommand @command)
        {
            var result = await mediator.Send(@command);

            return(result ?
                   (IActionResult)Ok(result) :
                   (IActionResult)BadRequest());
        }