public async Task <RoomReading> Add(RoomReading reading) { _dbContext.RoomReadings.Add(reading); await _dbContext.SaveChangesAsync(); return(reading); }
public async Task <IActionResult> Create([FromBody] RoomReadingViewModel model) { if (model == null) { return(StatusCode(400, "Invalid parameter(s).")); } RoomReading roomReading = new RoomReading { DeviceId = model.DeviceId, CreatedOn = model.CreatedOn, Type = model.Type, Value = model.Value }; //Insert room reading var result = await _roomReadingRepository.Add(roomReading); if (result == null) { return(StatusCode(500, "A problem occured while saving the reading. Please try again!")); } return(Ok(new RoomReadingViewModel { DeviceId = result.DeviceId, CreatedOn = result.CreatedOn, Type = result.Type, Value = result.Value })); }