From a9f6106c6e590f57d631751295ea8211a5cc3aa4 Mon Sep 17 00:00:00 2001 From: RaidMax Date: Mon, 18 Nov 2019 09:25:39 -0600 Subject: [PATCH] fix silly mistake with trying to assign something to an object that could be null --- SharedLibraryCore/Services/ClientService.cs | 36 +++------------------ 1 file changed, 5 insertions(+), 31 deletions(-) diff --git a/SharedLibraryCore/Services/ClientService.cs b/SharedLibraryCore/Services/ClientService.cs index f62ebbdd2..3733fb67f 100644 --- a/SharedLibraryCore/Services/ClientService.cs +++ b/SharedLibraryCore/Services/ClientService.cs @@ -114,31 +114,6 @@ namespace SharedLibraryCore.Services var aliases = await iqAliases.ToListAsync(); - //// update each of the aliases where this is no IP but the name is identical - //foreach (var alias in aliases.Where(_alias => (_alias.IPAddress == null || _alias.IPAddress == 0))) - //{ - // alias.IPAddress = ip; - //} - - //// remove any possible duplicates after updating - //foreach (var aliasGroup in aliases.GroupBy(_alias => new { _alias.IPAddress, _alias.Name }) - // .Where(_group => _group.Count() > 1)) - //{ - // var oldestDuplicateAlias = aliasGroup.OrderBy(_alias => _alias.DateAdded).First(); - - // entity.CurrentServer.Manager.GetLogger(0).WriteDebug($"Oldest duplicate is {oldestDuplicateAlias.AliasId}"); - - // await context.Clients.Where(_client => aliasGroup.Select(_grp => _grp.AliasId).Contains(_client.CurrentAliasId)) - // .ForEachAsync(_client => _client.CurrentAliasId = oldestDuplicateAlias.AliasId); - - // var duplicateAliases = aliasGroup.Where(_alias => _alias.AliasId != oldestDuplicateAlias.AliasId); - // context.RemoveRange(duplicateAliases); - - // await context.SaveChangesAsync(); - - // entity.CurrentServer.Manager.GetLogger(0).WriteDebug($"Removed duplicate aliases {string.Join(",", duplicateAliases.Select(_alias => _alias.AliasId))}"); - //} - // see if they have a matching IP + Name but new NetworkId var existingExactAlias = aliases.FirstOrDefault(a => a.Name == name && a.IPAddress == ip); bool hasExactAliasMatch = existingExactAlias != null; @@ -318,7 +293,6 @@ namespace SharedLibraryCore.Services // todo: this needs to be optimized for large linked accounts using (var context = new DatabaseContext(true)) { - var client = context.Clients .Select(_client => new EFClient() { @@ -338,6 +312,11 @@ namespace SharedLibraryCore.Services }) .FirstOrDefault(_client => _client.ClientId == entityId); + if (client == null) + { + return null; + } + client.AliasLink = new EFAliasLink() { AliasLinkId = client.AliasLinkId, @@ -350,11 +329,6 @@ namespace SharedLibraryCore.Services }).ToListAsync() }; - if (client == null) - { - return null; - } - var foundClient = new { Client = client,