public async Task <SumpPump> Pumps(string pumpId) { DeviceTwinEntity <SumpPumpSettingEntity> entity = await TwinRepository.ById(pumpId); var topDataPointQuery = await DataPointRepository.Top(pumpId, 1); DataPointEntity currentData = topDataPointQuery.FirstOrDefault(); var partialPump = Mapper.Map <DeviceTwinEntity <SumpPumpSettingEntity>, SumpPump>(entity); partialPump.LastPoint = Mapper.Map <DataPointEntity, DataPoint>(currentData); return(partialPump); }
public async Task Update(DeviceTwinEntity <T> entity) { DeviceTwinUpdateEntity <T> patchEntity = Mapper.Map <DeviceTwinUpdateEntity <T> >(entity); var method = new HttpMethod("PATCH"); HttpRequestMessage request = new HttpRequestMessage(method, string.Format("/twins/{0}?api-version=2016-11-14", entity.DeviceId)); string json = JsonConvert.SerializeObject(patchEntity, JsonSettings); request.Content = new StringContent(json, Encoding.UTF8, "application/json"); request.Headers.Authorization = new AuthenticationHeaderValue("SharedAccessSignature", GetSharedAccessSignature(Config.SharedAccessKeyName, Config.SharedAccessKey, Config.HostName, new TimeSpan(1, 0, 0))); var response = await client.SendAsync(request); response.EnsureSuccessStatusCode(); }
public async Task <IActionResult> UpdatePump(string pumpId, [FromBody] SumpPump pump) { if (pump == null || pump.PumpId != pumpId) { return(BadRequest()); } DeviceTwinEntity <SumpPumpSettingEntity> twinPump = await TwinRepository.ById(pumpId); if (twinPump == null) { return(NotFound()); } var updatePump = Mapper.Map <SumpPump, DeviceTwinEntity <SumpPumpSettingEntity> >(pump); TwinRepository.Update(updatePump); return(new NoContentResult()); }