public override async Task <WeatherForecast> Handle(PostWeatherForecastCommand command, CancellationToken cancellationToken) { var valid = await IsValidAsync(command, cancellationToken); if (!valid) { return(null); } var weatherForecast = new WeatherForecast( command.Date, command.TemperatureC, command.Summary ); await _weatherForecastRepository.AddAsync(weatherForecast, cancellationToken); await _weatherForecastRepository.SaveChangesAsync(cancellationToken); var @event = new WeatherForecastCreatedEvent(weatherForecast.WeatherForecastId); await _bus.RaiseEventAsync(@event, cancellationToken); return(weatherForecast); }
public async Task <ActionResult> Create([Bind(Include = "Id,City,TemperatureCelsius,Description")] WeatherForecast weatherForecast) { if (ModelState.IsValid) { await _repo.AddAsync(weatherForecast); return(RedirectToAction("Index")); } return(View(weatherForecast)); }