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); }
public async Task <IActionResult> Post([FromBody] CreateWeatherForecastCommand command) { var response = await _mediator.Send(command); return(response.Error ? (IActionResult)BadRequest(response) : Accepted(response)); }