public Response <DeviceDetailsDto> Save(DeviceDetailsDto deviceDetailsDto) { using (UnitOfWork unitOfWork = new UnitOfWork()) { return(unitOfWork.DeviceDetails.Save(deviceDetailsDto, DeviceDetailsMappers.Instance.MapToDeviceDetailsDto)); } }
public async Task <IActionResult> PostDevice([FromBody] DeviceDetailsDto deviceToCreate) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var createdDevice = await _service.CreateDevice(_mapper.Map <Device>(deviceToCreate)); return(CreatedAtAction("GetDevice", new { createdDevice.Id }, createdDevice)); }
public DeviceDetailsDto MapToDeviceDetailsDto(SqlDataReader sqlDataReader) { DeviceDetailsDto deviceDetailsDto = new DeviceDetailsDto(); deviceDetailsDto.Id = sqlDataReader["Id"].ToInteger(); deviceDetailsDto.DeviceId = sqlDataReader["DeviceId"].ToString(); deviceDetailsDto.DeviceName = sqlDataReader["DeviceName"].ToString(); deviceDetailsDto.DevicePlatform = sqlDataReader["DevicePlatform"].ToString(); deviceDetailsDto.DeviceSerialNumber = sqlDataReader["DeviceSerialNumber"].ToString(); deviceDetailsDto.CreateDate = sqlDataReader["CreateDate"].ToDateTime(); return(deviceDetailsDto); }
public async Task <IActionResult> PatchDevice([FromRoute] Guid id, [FromBody] DeviceDetailsDto device) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != device.Id) { return(BadRequest()); } var result = await _service.UpdateDevice(id, _mapper.Map <Device>(device)); if (result == null) { BadRequest(); } return(Ok(result)); }
public async Task <IActionResult> Details(string id) { var dto = new DeviceDetailsDto(); dto.DeviceId = id; var rm = RegistryManager .CreateFromConnectionString( _configuration["IoTHubConnectionString"]); var twin = await rm.GetTwinAsync(id); if (twin.Properties.Desired.Contains("SetPoint")) { dto.SetPoint = (decimal)(float)twin.Properties.Desired["SetPoint"]; } if (twin.Properties.Desired.Contains("AlarmPoint")) { dto.AlarmPoint = (decimal)(float)twin.Properties.Desired["AlarmPoint"]; } return(View(dto)); }
public HttpResponseMessage SaveDeviceDetails(DeviceDetailsDto deviceDetailsDto) { deviceDetailsDto.CrudStatus = CrudStatus.CREATE; return(Request.CreateResponse <Response <DeviceDetailsDto> >(HttpStatusCode.OK, deviceDetailsManager.Save(deviceDetailsDto))); }