public async Task <Unit> Handle(UpdateClientCommand command, CancellationToken cancellationToken) { var client = await _context.Clients .SingleOrDefaultAsync(x => x.Id == command.Id, cancellationToken); if (client == null) { throw new NullReferenceException($"Client with id #{command.Id} could not be found."); } // Ensure client is unique await _clientValidator.EnsureUniqueClientOnUpdate( client.Id, command.Client.Name, command.Client.AssignedIp, client.ServerId, cancellationToken ); // Update properties client.Name = command.Client.Name; client.Description = command.Client.Description; client.AssignedIp = command.Client.AssignedIp.ToAddress(); client.IsRevoked = command.Client.IsRevoked ?? client.IsRevoked; client.PublicKey = command.Client.PublicKey; await _context.SaveChangesAsync(cancellationToken); return(Unit.Value); }