public static void CanUpdate(AppClients clients, UpdateClient command, Roles roles) { Guard.NotNull(command, nameof(command)); var client = GetClientOrThrow(clients, command.Id); Validate.It(() => "Cannot update client.", e => { if (string.IsNullOrWhiteSpace(command.Id)) { e(Not.Defined("Client id"), nameof(command.Id)); } if (string.IsNullOrWhiteSpace(command.Name) && command.Role == null) { e(Not.DefinedOr("name", "role"), nameof(command.Name), nameof(command.Role)); } if (command.Role != null && !roles.ContainsKey(command.Role)) { e(Not.Valid("role"), nameof(command.Role)); } if (client == null) { return; } if (!string.IsNullOrWhiteSpace(command.Name) && string.Equals(client.Name, command.Name)) { e(Not.New("Client", "name"), nameof(command.Name)); } if (command.Role == client.Role) { e(Not.New("Client", "role"), nameof(command.Role)); } }); }