From f82bf69ceee3b61dc88c16bbb9aac695ddb7ae75 Mon Sep 17 00:00:00 2001 From: Jared Goodwin Date: Thu, 2 Dec 2021 12:40:35 -0800 Subject: [PATCH] Fixed error when trying to save device back into group "None". --- .../Components/Devices/DevicesFrame.razor.cs | 33 +++++++++---------- Server/Services/DataService.cs | 16 +++++++-- 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/Server/Components/Devices/DevicesFrame.razor.cs b/Server/Components/Devices/DevicesFrame.razor.cs index 3ea35d16..b283389e 100644 --- a/Server/Components/Devices/DevicesFrame.razor.cs +++ b/Server/Components/Devices/DevicesFrame.razor.cs @@ -221,29 +221,26 @@ namespace Remotely.Server.Components.Devices continue; } - if (_selectedGroupId == _deviceGroupNone && - !string.IsNullOrWhiteSpace(device.DeviceGroupID)) - { - continue; - } - else if (_selectedGroupId != _deviceGroupAll && - _selectedGroupId != device.DeviceGroupID) - { - continue; - } - if (!string.IsNullOrWhiteSpace(_filter) && - device.Alias?.Contains(_filter, StringComparison.OrdinalIgnoreCase) != true && - device.CurrentUser?.Contains(_filter, StringComparison.OrdinalIgnoreCase) != true && - device.DeviceName?.Contains(_filter, StringComparison.OrdinalIgnoreCase) != true && - device.Notes?.Contains(_filter, StringComparison.OrdinalIgnoreCase) != true && - device.Platform?.Contains(_filter, StringComparison.OrdinalIgnoreCase) != true && - device.Tags?.Contains(_filter, StringComparison.OrdinalIgnoreCase) != true) + device.Alias?.Contains(_filter, StringComparison.OrdinalIgnoreCase) != true && + device.CurrentUser?.Contains(_filter, StringComparison.OrdinalIgnoreCase) != true && + device.DeviceName?.Contains(_filter, StringComparison.OrdinalIgnoreCase) != true && + device.Notes?.Contains(_filter, StringComparison.OrdinalIgnoreCase) != true && + device.Platform?.Contains(_filter, StringComparison.OrdinalIgnoreCase) != true && + device.Tags?.Contains(_filter, StringComparison.OrdinalIgnoreCase) != true) { continue; } - _filteredDevices.Add(device); + if (_selectedGroupId == _deviceGroupAll || + _selectedGroupId == device.DeviceGroupID || + ( + _selectedGroupId == _deviceGroupNone && + string.IsNullOrWhiteSpace(device.DeviceGroupID + ))) + { + _filteredDevices.Add(device); + } } if (!string.IsNullOrWhiteSpace(_selectedSortProperty)) diff --git a/Server/Services/DataService.cs b/Server/Services/DataService.cs index 4b5cf474..cef524e2 100644 --- a/Server/Services/DataService.cs +++ b/Server/Services/DataService.cs @@ -1889,14 +1889,26 @@ namespace Remotely.Server.Services { using var dbContext = GetDbContext(); - var device = dbContext.Devices.Find(deviceID); + var device = dbContext.Devices + .Include(x => x.DeviceGroup) + .FirstOrDefault(x => x.ID == deviceID); if (device == null) { return; } + if (string.IsNullOrWhiteSpace(deviceGroupID)) + { + device.DeviceGroup?.Devices?.RemoveAll(x => x.ID == deviceID); + device.DeviceGroup = null; + device.DeviceGroupID = null; + } + else + { + device.DeviceGroupID = deviceGroupID; + } + device.Tags = tag; - device.DeviceGroupID = deviceGroupID; device.Alias = alias; device.Notes = notes; device.WebRtcSetting = webRtcSetting;