public async Task <bool> DeleteAsync(Core.Common.JsonWebKey jsonWebKey) { using (var transaction = _context.Database.BeginTransaction()) { try { var jsonWebKeyToBeRemoved = await _context.JsonWebKeys.FirstOrDefaultAsync(j => j.Kid == jsonWebKey.Kid).ConfigureAwait(false); if (jsonWebKeyToBeRemoved == null) { return(false); } _context.JsonWebKeys.Remove(jsonWebKeyToBeRemoved); await _context.SaveChangesAsync().ConfigureAwait(false); transaction.Commit(); } catch (Exception ex) { _managerEventSource.Failure(ex); transaction.Rollback(); return(false); } } return(true); }
public async Task <bool> InsertAsync(Core.Common.JsonWebKey jsonWebKey) { using (var transaction = _context.Database.BeginTransaction()) { try { var keyOperations = string.Empty; var x5u = string.Empty; if (jsonWebKey.KeyOps != null) { var keyOperationNumbers = jsonWebKey.KeyOps.Select(s => (int)s); keyOperations = string.Join(",", keyOperationNumbers); } if (jsonWebKey.X5u != null) { x5u = jsonWebKey.X5u.AbsoluteUri; } var newJsonWebKeyRecord = new Models.JsonWebKey { Kid = jsonWebKey.Kid, Alg = (Models.AllAlg)jsonWebKey.Alg, Kty = (Models.KeyType)jsonWebKey.Kty, Use = (Models.Use)jsonWebKey.Use, KeyOps = keyOperations, SerializedKey = jsonWebKey.SerializedKey, X5t = jsonWebKey.X5t, X5tS256 = jsonWebKey.X5tS256, X5u = x5u }; _context.JsonWebKeys.Add(newJsonWebKeyRecord); await _context.SaveChangesAsync().ConfigureAwait(false); transaction.Commit(); } catch (Exception ex) { _managerEventSource.Failure(ex); transaction.Rollback(); return(false); } } return(true); }