public async Task <IActionResult> Post([FromBody] SensorDataPostModel requestSensorData) { _logger.LogInformation($"{nameof(SensorDataController.Post)} called."); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var userSensor = _userSensorService.GetByMacAddress(requestSensorData.MacAddress); if (userSensor == null) { return(BadRequest($"Sensor with MAC: {requestSensorData.MacAddress} does not exist.")); } await _temperatureService.AddAsync(new SensorTemperature { Humidity = requestSensorData.Humidity, Temperature = requestSensorData.Temperature, UserSensor = userSensor }); return(Ok()); }
public async Task <IActionResult> Post([FromBody] TemperatureAddDto temperature) { try { var id = await _temperatureService.AddAsync(temperature); var saveResult = await _temperatureService.SaveAsync(); if (saveResult == 0) { _logger.LogError("Unable to add a new temperature at this time"); return(StatusCode(StatusCodes.Status500InternalServerError)); } return(Ok(id)); } catch (Exception exception) { _logger.LogError(exception, "An error occurred while trying to add a new temperature"); return(StatusCode(StatusCodes.Status500InternalServerError)); } }