public IActionResult Create([FromBody] MeasurementModel model) { try { var weatherStation = _measurementService.FindWeatherStation(model.Location.Name); if (weatherStation == null) { weatherStation = new LocalWeatherStation { Name = model.Location.Name, Longitude = model.Location.Longitude, Latitude = model.Location.Latitude }; } var measurement = new Measurement { LocalWeatherStation = weatherStation, Temperature = model.Temperature, AirPressure = model.AirPressure, Humidity = model.Humidity, Time = DateTime.ParseExact(model.Time, "dd-MM-yyyy HH:mm:ss", null) }; if (weatherStation.Measurements == null) { weatherStation.Measurements = new List <Measurement>(); } weatherStation.Measurements.Add(measurement); _measurementService.Create(measurement); // Notify Hub _chatHub.Clients.All.SendAsync("ReceiveMessage", "New Data in ", model.Location.Name); return(RedirectToAction(nameof(Index))); } catch { return(NotFound()); } }
private void Button_Click(object sender, RoutedEventArgs e) { var vm = (InputPageViewModel)this.DataContext; var meas = new Measurement(); meas.ID = vm.ID; meas.Name = vm.Name; meas.Timestamp = vm.Timestamp; meas.UoM = vm.UoM; meas.Value = vm.Value; var entry = measurementService.Get(vm.ID); if (entry == null) { measurementService.Create(meas); } else { measurementService.Update(meas); } }
public ActionResult <Measurements> Create(Measurements Measurement) { _measurementService.Create(Measurement); return(CreatedAtRoute("GetMeasurement", new { id = Measurement.ID.ToString() }, Measurement)); }