Exemplo n.º 1
0
        public async Task <CommandHandlingResult> Handle(UpdateEmployeeCredentialsCommand cmd, IEventPublisher publisher)
        {
            if (string.IsNullOrEmpty(cmd.Password))
            {
                publisher.PublishEvent(new EmployeeUpdateCompletedEvent
                {
                    Id = cmd.EmployeeId
                });

                _chaosKitty.Meow("Issue with RabbitMq publishing EmployeeUpdateCompletedEvent");

                return(CommandHandlingResult.Ok());
            }

            await _employeeCredentialsService.UpdateAsync(new EmployeeCredentials
            {
                EmployeeId = cmd.EmployeeId,
                Email      = cmd.Email,
                MerchantId = cmd.MerchantId,
                Password   = cmd.Password,
            });

            publisher.PublishEvent(new EmployeeCredentialsUpdatedEvent
            {
                EmployeeId = cmd.EmployeeId,
                MerchantId = cmd.MerchantId
            });

            _chaosKitty.Meow("Issue with RabbitMq publishing EmployeeCredentialsUpdatedEvent");

            return(CommandHandlingResult.Ok());
        }
Exemplo n.º 2
0
        public async Task <IActionResult> UpdateAsync([FromBody] UpdateCredentialsModel model)
        {
            try
            {
                var credentials = Mapper.Map <EmployeeCredentials>(model);

                await _employeeCredentialsService.UpdateAsync(credentials);
            }
            catch (InvalidOperationException e)
            {
                _log.Warning(e.Message, e,
                             model.MerchantId
                             .ToContext(nameof(model.MerchantId))
                             .ToContext(nameof(model.EmployeeId), model.EmployeeId)
                             .ToContext(nameof(model.Email), model.Email.SanitizeEmail()));

                return(BadRequest(ErrorResponse.Create(e.Message)));
            }

            return(NoContent());
        }