public async Task SetApprovedAsync(string customerId, string publicAddress, string signature, Money18 fee, TransactionContext txContext = null) { using (var context = _contextFactory.CreateDataContext(txContext)) { var entity = new WalletLinkingRequestEntity { CustomerId = customerId }; context.LinkingRequests.Attach(entity); entity.PublicAddress = publicAddress; entity.Signature = signature; entity.Timestamp = DateTime.UtcNow; entity.Fee = fee; try { await context.SaveChangesAsync(); } catch (DbUpdateException e) { _log.Error(e, EntityNotFoundWhenApproving); throw new InvalidOperationException(EntityNotFoundWhenApproving); } } }
public async Task SetPubliclyConfirmedAsync(string customerId, TransactionContext txContext = null) { using (var context = _contextFactory.CreateDataContext(txContext)) { var entity = new WalletLinkingRequestEntity { CustomerId = customerId }; context.LinkingRequests.Attach(entity); entity.IsConfirmedInPublic = true; entity.Timestamp = DateTime.UtcNow; try { await context.SaveChangesAsync(); } catch (DbUpdateException e) { _log.Error(e, EntityNotFoundWhenConfirming); throw new InvalidOperationException(EntityNotFoundWhenConfirming); } } }
public async Task DeleteByIdAsync(string customerId, TransactionContext txContext = null) { using (var context = _contextFactory.CreateDataContext(txContext)) { var entity = new WalletLinkingRequestEntity { CustomerId = customerId }; context.LinkingRequests.Attach(entity); context.LinkingRequests.Remove(entity); try { await context.SaveChangesAsync(); } catch (DbUpdateException e) { _log.Error(e, CannotDeleteLinkingRequest); throw new InvalidOperationException(CannotDeleteLinkingRequest); } } }
public async Task AddAsync(string customerId, string privateAddress, string linkCode, TransactionContext txContext = null) { using (var context = _contextFactory.CreateDataContext(txContext)) { var entity = WalletLinkingRequestEntity.Create(customerId, privateAddress, linkCode); await context.LinkingRequests.AddAsync(entity); try { await context.SaveChangesAsync(); } catch (DbUpdateException e) { if (e.InnerException is PostgresException sqlException && sqlException.SqlState == PostgresErrorCodes.UniqueViolation) { throw new LinkingRequestAlreadyExistsException(customerId); } throw; } } }