public async Task <IActionResult> OnPostAsync(CustomDevice customDevice) { if (!User.Identity.IsAuthenticated) { return(Redirect("/")); } var tokenData = await SmartMeOAuthConfiguration.GetAccessToken(HttpContext); return(await DevicesApi.UpdateCustomDeviceAsync(tokenData.AccessToken, customDevice, new ResultHandler <CustomDevice> { OnSuccess = (empty) => { // Trigger another GET to show the updated custom device return Redirect("/Devices/UpdateCustomDevice"); }, OnError = DefaultErrorHandler.Handle })); }
public static async Task CustomDevicesAsync(UserPassword credentials) { // Add Custom Device { Helpers.WriteConsoleTitle("Add a custom device"); await DevicesApi.AddCustomDeviceAsync(credentials, new CustomDevice { Id = new Guid(), Name = "CustomDeviceTest", Serial = 0, ValueDate = DateTime.UtcNow, Values = new List <CustomDeviceValue> { new CustomDeviceValue { Name = "SomeVoltageValue", Value = 5.6 }, new CustomDeviceValue { Name = "SomeTemperatureValue", Value = 12.1 } } }); } CustomDevice sampleDevice; // Get Custom Devices { Helpers.WriteConsoleTitle("Get custom devices"); List <CustomDevice> customDevices = await DevicesApi.GetCustomDevicesAsync(credentials); foreach (CustomDevice customDevice in customDevices) { if (customDevice != null) { Console.WriteLine($"Id: {customDevice.Id}, Name: {customDevice.Name}"); } } sampleDevice = customDevices.First(); } // Update Custom Device { Helpers.WriteConsoleTitle("Update a custom device"); List <CustomDevice> customDevices = await DevicesApi.GetCustomDevicesAsync(credentials); foreach (CustomDevice customDevice in customDevices) { if (customDevice != null) { customDevice.Name = "UpdatedCustomDeviceTest"; await DevicesApi.UpdateCustomDeviceAsync(credentials, customDevice); break; } } } // Get Custom Device by Id { Helpers.WriteConsoleTitle("Get custom device by id"); CustomDevice customDevice = await DevicesApi.GetCustomDeviceAsync(credentials, sampleDevice.Id); Console.WriteLine($"Id: {customDevice.Id}, Name: {customDevice.Name}"); } }