Beispiel #1
0
        public void VerifyOrderExpiration()
        {
            IEnumerable <Order> orders = _orderRepository.GetAll()
                                         .Where(x => (x.Status.Status == OrderStatus.OrderStatusValue.PaymentPending || x.Status.Status == OrderStatus.OrderStatusValue.Created) && DateTime.Today > x.CreationTime.AddDays(_clientOptions.OrderDaysToExpire)).ToList();

            foreach (Order order in orders)
            {
                using var unitOfWork = UnitOfWorkManager.Begin();

                _orderDomainService.ExpireOrder(order);

                if (order.Type.Type == OrderType.OrderTypeValue.Subscription || order.Type.Type == OrderType.OrderTypeValue.RenewSubscription)
                {
                    SubscriptionCycleOrder cycleOrder = _subscriptionCycleOrderRepository.GetAll().Include(x => x.SubscriptionCycle).ThenInclude(x => x.Subscription).Single(x => x.OrderId == order.Id);

                    _subscriptionCycleDomainService.CancelSubscriptionCycle(cycleOrder.SubscriptionCycle);

                    if (order.Type.Type == OrderType.OrderTypeValue.RenewSubscription)
                    {
                        _subscriptionDomainService.SuspendSubscription(cycleOrder.SubscriptionCycle.Subscription);
                    }
                    else if (order.Type.Type == OrderType.OrderTypeValue.Subscription)
                    {
                        _subscriptionDomainService.CancelSubscription(cycleOrder.SubscriptionCycle.Subscription);
                    }

                    _subscriptionCycleOrderRepository.Update(cycleOrder);
                }

                unitOfWork.Complete();
            }
        }