From 461298d14d318df3a5e0928fd6373c66e340449f Mon Sep 17 00:00:00 2001 From: Stone_Red <56473591+Stone-Red-Code@users.noreply.github.com> Date: Thu, 4 May 2023 22:09:27 +0200 Subject: [PATCH] Fix delete things --- .../Elektrifikatsiya/Pages/Settings.razor | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/Elektrifikatsiya/Elektrifikatsiya/Pages/Settings.razor b/src/Elektrifikatsiya/Elektrifikatsiya/Pages/Settings.razor index 60e82b6..b4afa9f 100644 --- a/src/Elektrifikatsiya/Elektrifikatsiya/Pages/Settings.razor +++ b/src/Elektrifikatsiya/Elektrifikatsiya/Pages/Settings.razor @@ -8,6 +8,7 @@ @using FluentResults @inject IDeviceManagmentService DeviceManagmentService +@inject IMessageService MessageService
@@ -176,7 +177,7 @@ private void OnSave() { - if (hideButtonSettings || DeviceCopy is null) + if (hideButtonSettings || DeviceCopy is null || SelectedDevice is null) { } @@ -187,9 +188,22 @@ } } - private void Delete(Device contextItem) + private async Task Delete(Device contextItem) { - DeviceManagmentService.UnregisterDevice(contextItem.MacAddress); - } + bool succ = await MessageService.Confirm($"Do you really want to delete the device \"{contextItem.Name}\"?"); + if(!succ) + { + return; + } + + await DeviceManagmentService.UnregisterDevice(contextItem.MacAddress); + + int index = plugs.FindIndex(x => x.MacAddress == contextItem.MacAddress); + + if(index != -1) + { + plugs.RemoveAt(index); + } + } } \ No newline at end of file