public override EncryptionKey DeleteKey(string walletId, string address, string keyId, IDbConnectorService dbservice) { EncryptionKey respkey = null; try { if (EconomyMainContext.Wallets.TryGetValue(walletId, out var wallet)) { if (wallet.Accounts.TryGetValue(address, out var account)) { var key = account.AccountKeys.FirstOrDefault(k => k.Id.ToString() == keyId); if (key != null) { respkey = key; account.AccountKeys.Remove(key); } if (account.AccountKey != null) { if (account.AccountKey.Id.ToString() == keyId) { account.AccountKey = null; } } } } if (EconomyMainContext.WorkWithDb) { var k = dbservice.GetKey(new Guid(keyId)); if (k != null) { respkey = k; dbservice.DeleteKey(keyId); } } return(respkey); } catch (Exception ex) { log.Error("Cannot delete the key!", ex); throw new Exception($"Cannot delete the key!"); } }