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

            agent.UpdateSocialMedia(@command.Facebook, @command.Instagram, @command.Twitter, @command.LinkedIn);

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

            var update = Builders <Agent> .Update
                         .Set("Facebook", agent.Facebook)
                         .Set("Instagram", agent.Instagram)
                         .Set("Twitter", agent.Twitter)
                         .Set("LinkedIn", agent.LinkedIn)
                         .CurrentDate("UpdatedDate");

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

            await mediator.DispatchDomainEventsAsync(agent);

            return(true);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> UpdateAgentSocialMedia([FromBody] UpdateAgentSocialMediaCommand @command)
        {
            var result = await mediator.Send(@command);

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