Fixed error when trying to save device back into group "None".

This commit is contained in:
Jared Goodwin 2021-12-02 12:40:35 -08:00
parent 2c00af892e
commit f82bf69cee
2 changed files with 29 additions and 20 deletions

View File

@ -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))

View File

@ -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;