Ejemplo n.º 1
0
        public async Task <IActionResult> PostAsync([FromBody] PostWeatherForecastViewModel postWeatherForecast, CancellationToken cancellationToken)
        {
            var command = _mapper.Map <PostWeatherForecastCommand>(postWeatherForecast);
            var result  = await _mediator.SendCommandAsync <PostWeatherForecastCommand, WeatherForecast>(command, cancellationToken);

            var response = _mapper.Map <WeatherForecast, WeatherForecastViewModel>(result);

            var simpleJob = new WeatherForecastUpdatedJob(response.WeatherForecastId);
            var jobId     = _mediator.RaiseJob(simpleJob);

            var continuedJob = new WeatherForecastContinuedJob(response.WeatherForecastId, jobId);

            _mediator.RaiseJob(continuedJob);

            return(ResponseRedirect("Get", new { id = response?.WeatherForecastId }));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> PostAsync([FromBody] PostWeatherForecastViewModel postWeatherForecast, CancellationToken cancellationToken, [FromServices] DbTransaction dbTransaction)
        {
            // SQLite does not support multiple transactions, to use transactions do not use persistent jobs
            // Uncomment the '.UseTransaction( )' line at Startup
            await using var transaction = new Transactions(dbTransaction);
            var command = _mapper.Map <PostWeatherForecastCommand>(postWeatherForecast);
            var result  = await _mediator.SendCommandAsync <PostWeatherForecastCommand, WeatherForecast>(command, cancellationToken);

            var response = _mapper.Map <WeatherForecast, WeatherForecastViewModel>(result);

            await transaction.CommitAsync( );

            var simpleJob = new WeatherForecastUpdatedJob(response.WeatherForecastId);
            var jobId     = _mediator.RaiseJob(simpleJob);

            var continuedJob = new WeatherForecastContinuedJob(response.WeatherForecastId, jobId);

            _mediator.RaiseJob(continuedJob);

            return(ResponseRedirect("Get", new { id = response?.WeatherForecastId }));
        }