Beispiel #1
0
        public async Task <IActionResult> RegisterEmployee(RegisterEmployeeCommand registerEmployee)
        {
            var result = await Mediator.Send(registerEmployee);

            if (result.Success == false)
            {
                return(result.ApiResult);
            }

            return(Ok(result.Data));
        }
        public async Task<CommandHandlingResult> Handle(RegisterEmployeeCommand command, IEventPublisher publisher)
        {
            Employee employee;

            try
            {
                employee = await _employeeService.AddAsync(Mapper.Map<Employee>(command));
            }
            catch (Exception e)
            {
                if (e is MerchantNotFoundException merchantEx)
                    _log.WarningWithDetails(merchantEx.Message, new {merchantEx.MerchantId});

                if (e is EmployeeExistException employeeEx)
                    _log.WarningWithDetails(employeeEx.Message, new { command.Email });

                publisher.PublishEvent(new EmployeeRegistrationFailedEvent
                {
                    Email = command.Email,
                    Error = e.Message
                });

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

                return CommandHandlingResult.Ok();
            }

            publisher.PublishEvent(new EmployeeRegisteredEvent
            {
                Id = employee.Id,
                Email = employee.Email,
                MerchantId = employee.MerchantId,
                Password = command.Password
            });

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

            return CommandHandlingResult.Ok();
        }