示例#1
0
        /// <summary>
        /// Removes the purchase from persistence.
        /// </summary>
        /// <returns>A task.</returns>
        public async Task RollbackAsync()
        {
            if (Result != null)
            {
                try
                {
                    // delete the inserted row
                    await CustomerPurchasesRepository.DeleteAsync(Result).ConfigureAwait(false);
                }
                catch (Exception deletionProblem)
                {
                    if (deletionProblem.IsFatal())
                    {
                        throw;
                    }

                    Trace.TraceError(
                        "RecordPurchase.RollbackAsync failed: {0}, Customer ID: {1}, ID: {2}",
                        deletionProblem,
                        Result.CustomerId,
                        Result.Id);

                    // TODO: Notify the system integrity recovery component
                }

                Result = null;
            }
        }
示例#2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RecordPurchase"/> class.
        /// </summary>
        /// <param name="repository">A customer purchases repository which manages customer purchases persistence.</param>
        /// <param name="newPurchaseRecord">The new customer purchase to record.</param>
        public RecordPurchase(CustomerPurchasesRepository repository, CustomerPurchaseEntity newPurchaseRecord)
        {
            repository.AssertNotNull(nameof(repository));
            newPurchaseRecord.AssertNotNull(nameof(newPurchaseRecord));

            this.CustomerPurchasesRepository = repository;
            this.CustomerPurchaseToPersist   = newPurchaseRecord;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="PersistNewlyPurchasedSubscriptions"/> class.
        /// </summary>
        /// <param name="customerId">The ID of the customer who performed the purchases.</param>
        /// <param name="subscriptionsRepository">The customer subscriptions repository used to persist the subscriptions.</param>
        /// <param name="purchasesRepository">The customer purchases repository used to persist the purchases.</param>
        /// <param name="acquireInputsFunction">The function used to obtain the order and the list of purchase line items associated with their partner offers.</param>
        public PersistNewlyPurchasedSubscriptions(
            string customerId,
            CustomerSubscriptionsRepository subscriptionsRepository,
            CustomerPurchasesRepository purchasesRepository,
            Func <Tuple <Order, IEnumerable <PurchaseLineItemWithOffer> > > acquireInputsFunction)
        {
            customerId.AssertNotEmpty(nameof(customerId));
            subscriptionsRepository.AssertNotNull(nameof(subscriptionsRepository));
            purchasesRepository.AssertNotNull(nameof(purchasesRepository));
            acquireInputsFunction.AssertNotNull(nameof(acquireInputsFunction));

            this.CustomerId = customerId;
            this.CustomerSubscriptionsRepository = subscriptionsRepository;
            this.CustomerPurchasesRepository     = purchasesRepository;
            this.AcquireInput = acquireInputsFunction;
        }
示例#4
0
 /// <summary>
 /// Persists the purchase.
 /// </summary>
 /// <returns>A task.</returns>
 public async Task ExecuteAsync()
 {
     Result = await CustomerPurchasesRepository.AddAsync(CustomerPurchaseToPersist).ConfigureAwait(false);
 }