/// <summary> /// Removes a customer subscription. /// </summary> /// <param name="customerSubscriptionToRemove">The customer subscription to remove.</param> /// <returns>A task.</returns> public async Task DeleteAsync(CustomerSubscriptionEntity customerSubscriptionToRemove) { customerSubscriptionToRemove.AssertNotNull(nameof(customerSubscriptionToRemove)); var customerSubscriptionsTable = await this.ApplicationDomain.AzureStorageService.GetCustomerSubscriptionsTableAsync(); var deletionResult = await customerSubscriptionsTable.ExecuteAsync(TableOperation.Delete(new CustomerSubscriptionTableEntity(customerSubscriptionToRemove.CustomerId, customerSubscriptionToRemove.SubscriptionId) { ETag = "*" })); deletionResult.HttpStatusCode.AssertHttpResponseSuccess(ErrorCode.PersistenceFailure, "Failed to remove customer subscription", deletionResult.Result); }
/// <summary> /// Adds a new customer subscription. /// </summary> /// <param name="newCustomerSubscription">The new subscription information.</param> /// <returns>The just added customer subscription.</returns> public async Task <CustomerSubscriptionEntity> AddAsync(CustomerSubscriptionEntity newCustomerSubscription) { newCustomerSubscription.AssertNotNull(nameof(newCustomerSubscription)); CustomerSubscriptionTableEntity customerSubscriptionTableEntity = new CustomerSubscriptionTableEntity(newCustomerSubscription.CustomerId, newCustomerSubscription.SubscriptionId) { PartnerOfferId = newCustomerSubscription.PartnerOfferId, ExpiryDate = newCustomerSubscription.ExpiryDate }; var customerSubscriptionsTable = await this.ApplicationDomain.AzureStorageService.GetCustomerSubscriptionsTableAsync(); var insertionResult = await customerSubscriptionsTable.ExecuteAsync(TableOperation.Insert(customerSubscriptionTableEntity)); insertionResult.HttpStatusCode.AssertHttpResponseSuccess(ErrorCode.PersistenceFailure, "Failed to add customer subscription", insertionResult.Result); return(newCustomerSubscription); }
/// <summary> /// Updates a customer subscription. /// </summary> /// <param name="customerSubscriptionUpdates">The customer subscription updates.</param> /// <returns>The updated customer subscription.</returns> public async Task <CustomerSubscriptionEntity> UpdateAsync(CustomerSubscriptionEntity customerSubscriptionUpdates) { customerSubscriptionUpdates.AssertNotNull(nameof(customerSubscriptionUpdates)); var updateSubscriptionOperation = TableOperation.Replace(new CustomerSubscriptionTableEntity(customerSubscriptionUpdates.CustomerId, customerSubscriptionUpdates.SubscriptionId) { ExpiryDate = customerSubscriptionUpdates.ExpiryDate, PartnerOfferId = customerSubscriptionUpdates.PartnerOfferId, ETag = "*" }); var customerSubscriptionsTable = await this.ApplicationDomain.AzureStorageService.GetCustomerSubscriptionsTableAsync(); var updateResult = await customerSubscriptionsTable.ExecuteAsync(updateSubscriptionOperation); updateResult.HttpStatusCode.AssertHttpResponseSuccess(ErrorCode.PersistenceFailure, "Failed to update customer subscription", updateResult.Result); return(customerSubscriptionUpdates); }