public async Task <CommandHandlingResult> Handle(RegisterEmployeeCredentialsCommand cmd, IEventPublisher publisher) { try { await _employeeCredentialsService.RegisterAsync(new EmployeeCredentials { EmployeeId = cmd.EmployeeId, MerchantId = cmd.MerchantId, Email = cmd.Email, Password = cmd.Password, ForcePasswordUpdate = true, ForcePinUpdate = true }); } catch (InvalidOperationException e) { // employee already exists _log.Warning(e.Message, context: $"Command details: {cmd.ToJson()}"); } publisher.PublishEvent(new EmployeeCredentialsRegisteredEvent { EmployeeId = cmd.EmployeeId, MerchantId = cmd.MerchantId }); _chaosKitty.Meow("Issue with RabbitMq publishing EmployeeCredentialsRegisteredEvent"); return(CommandHandlingResult.Ok()); }
public async Task <IActionResult> RegisterAsync([FromBody] RegisterModel model) { try { var credentials = Mapper.Map <EmployeeCredentials>(model); await _employeeCredentialsService.RegisterAsync(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()); }