public IActionResult Create(DeviceModel device) { if (device != null && !string.IsNullOrEmpty(device.RegistrationId)) { try { var body = new DPSRequest(); body.RegistrationID = device.RegistrationId; if (!string.IsNullOrEmpty(device.Tags)) { body.Tags.Add("tags", device.Tags); } if (!string.IsNullOrEmpty(device.AllowedDevices)) { body.DesiredProperties.Add("allowed", device.AllowedDevices); } var dps = new DPSHelper(_config.GetSection("API_URL").Value); var result = dps.CreateDeviceRegistration(body).GetAwaiter().GetResult(); dynamic o = JsonConvert.DeserializeObject(result); device.PrimaryKey = (string)o.attestation.symmetricKey.primaryKey; device.SecondaryKey = (string)o.attestation.symmetricKey.secondaryKey; WriteDataStorage(device); } catch (Exception exp) { return(View(new ErrorViewModel { ErrorMessage = exp.Message })); } } return(View(device)); }
public IActionResult Delete(DeviceModel device) { if (device != null && !string.IsNullOrEmpty(device.RegistrationId)) { try { var body = new DPSRequest(); body.RegistrationID = device.RegistrationId; var dps = new DPSHelper(_config.GetSection("API_URL").Value); var result = dps.DeleteDeviceRegistration(body).GetAwaiter().GetResult(); DeleteFromDataStorage(device); } catch (Exception exp) { return(View(new ErrorViewModel { ErrorMessage = exp.Message })); } } return(View(device)); }