예제 #1
0
        public async Task <IActionResult> Add([FromBody] AddWeatherForecastRequest input)
        {
            try
            {
                var useCase = _serviceProvider.GetService <IAddWeatherForecastUseCase>();
                var result  = await useCase.Execute(input, PrincipalAccessor.Principal.GetUsernameFromClaim());

                return(CreatedAtAction(nameof(Get), new { version = Version, id = result }, input));
            }
            catch (Exception e)
            {
                _logger.LogError(e, e.Message);
                return(StatusCode(StatusCodes.Status500InternalServerError, e.Message));
            }
        }
예제 #2
0
        public async Task <Guid> Execute(AddWeatherForecastRequest input, string username)
        {
            var correlationId = CorrelationIdAccessor.CorrelationId;

            var weatherForecast = new WeatherForecastEntity(correlationId)
            {
                Temperature = input.TemperatureInCelsius, Summary = input.Summary, Date = input.Date
            };

            var command = new CreateWeatherForecastCommand(weatherForecast, username);
            await _commandDispatcher.Execute(command);

            var evt = _mapper.Map <WeatherForecastEntity, WeatherForecastCreatedEvent>(weatherForecast);

            _backgroundTaskQueue.Queue($"Publishing WeatherForecastCreatedEvent for {evt.Id}",
                                       (cancelationToken) => _eventDispatcher.Raise(evt));

            return(weatherForecast.Id);
        }