public async Task <IPaymentTransaction> GetLastByDateAsync(string clientId) { var partitionKey = PaymentTransactionEntity.GeneratePartitionKey(clientId); var entities = await _tableStorage.GetDataAsync(partitionKey); return(entities.OrderByDescending(itm => itm.Created).FirstOrDefault()); }
private static async Task UpdatePaymentTransaction(PaymentTransactionEntity transaction, string status) { var storageAccount = CloudStorageAccount.Parse(Environment.GetEnvironmentVariable("TableStorage")); var tableClient = storageAccount.CreateCloudTableClient(); var table = tableClient.GetTableReference("PaymentTransaction"); var retrieveOperation = TableOperation.Retrieve <PaymentTransactionEntity>(transaction.PartitionKey, transaction.RowKey); var retrievedResult = await table.ExecuteAsync(retrieveOperation); var updateEntity = (PaymentTransactionEntity)retrievedResult.Result; if (updateEntity != null) { updateEntity.Status = status; var updateOperation = TableOperation.Replace(updateEntity); await table.ExecuteAsync(updateOperation); } }
public async Task InsertAsync(IPaymentTransaction paymentTransaction) { var commonEntity = Mapper.Map <PaymentTransactionEntity>(paymentTransaction); commonEntity.PartitionKey = PaymentTransactionEntity.GeneratePartitionKey(); await _tableStorage.InsertAndGenerateRowKeyAsDateTimeAsync(commonEntity, paymentTransaction.Created); var entityByClient = Mapper.Map <PaymentTransactionEntity>(paymentTransaction); entityByClient.PartitionKey = PaymentTransactionEntity.GeneratePartitionKey(paymentTransaction.ClientId); entityByClient.RowKey = PaymentTransactionEntity.GenerateRowKey(paymentTransaction.Id); var index = AzureMultiIndex.Create(IndexPartitionKey, paymentTransaction.Id, commonEntity, entityByClient); await Task.WhenAll( _tableStorage.InsertAsync(entityByClient), _tableStorageIndices.InsertAsync(index) ); }
private static async Task <PaymentTransactionEntity> InsertPaymentTransaction(Order order) { var storageAccount = CloudStorageAccount.Parse(Environment.GetEnvironmentVariable("TableStorage")); var tableClient = storageAccount.CreateCloudTableClient(); var paymentTransactionEntity = new PaymentTransactionEntity(order.Id.ToString(), Guid.NewGuid().ToString()) { CustomerId = order.Customer.Id.ToString(), CreditCardNumber = order.Payment.CreditCardNumber, ExpirationDate = order.Payment.ExpirationDate, SecurityCode = order.Payment.SecurityCode, Status = "Pending" }; var table = tableClient.GetTableReference("PaymentTransaction"); var insertPaymentTransactionOperation = TableOperation.Insert(paymentTransactionEntity); await table.ExecuteAsync(insertPaymentTransactionOperation); return(paymentTransactionEntity); }