Recursive transaction repository implementation example
public class SuccessiveTransactionRepository : ISuccessiveTransactionRepository, IDomainService
    {
        private readonly ILinqRepository<QlikBarIssuedInvoice> _issuedInvoicesRepository;
        private readonly ILinqRepository<Subscription> _subscriptionRepository;
        private readonly IQlikBarInvoiceGenerator _invoiceGenerator;

        public SuccessiveTransactionRepository(ILinqRepository<QlikBarIssuedInvoice> issuedInvoicesRepository, ILinqRepository<Subscription> subscriptionRepository, IQlikBarInvoiceGenerator invoiceGenerator )
        {
            _issuedInvoicesRepository = issuedInvoicesRepository;
            _subscriptionRepository = subscriptionRepository;
            _invoiceGenerator = invoiceGenerator;
        }

        public IEnumerator<RedsysSuccessiveTransaction> GetEnumerator()
        {
            return _issuedInvoicesRepository.Query()
                                            .Where(x => x.IssueDate.HasValue)
                                            .Select(
                                                    x =>
                                                    new RedsysSuccessiveTransaction
                                                    {
                                                        Date = x.IssueDate.Value,
                                                        Order = x.Subscription.TransactionId
                                                    })
                                            .GetEnumerator();
        }
        IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); }

        public void Get(object identifier) { throw new NotImplementedException(); }

        public void Save(RedsysSuccessiveTransaction item)
        {
            Subscription subscription = _subscriptionRepository.Single(x => x.TransactionId == item.Order);
            QlikBarIssuedInvoice invoice = _invoiceGenerator.GenerateInvoice(subscription);
            invoice.IssueDate = item.Date;
            subscription.Invoices.Add(invoice);
            _subscriptionRepository.Update(subscription);
        }

        public void Update(RedsysSuccessiveTransaction item) { throw new NotImplementedException(); }
        public void Delete(RedsysSuccessiveTransaction item) { throw new NotImplementedException(); }
    }
Code Snippet
public class RecurringTransactionRepository : IRecurringTransactionRepository, IDomainService
    {
        private readonly ILinqRepository<Subscription> _subscriptionRepository;

        public RecurringTransactionRepository(ILinqRepository<Subscription> subscriptionRepository)
        {
            _subscriptionRepository = subscriptionRepository;
        }

        public IEnumerator<RedsysRecurringTransaction> GetEnumerator()
        {
            return _subscriptionRepository.Query()
                                          .Where(x => x.Gateway == "La Caixa" && x.Frequency == UnitOfTime.Month)
                                          .ToArray()
                                          .Select(
                                                  x =>
                                                  new RedsysRecurringTransaction
                                                  {
                                                      StartDate = x.StartDate,
                                                      Recurrences = 12,
                                                      Amount = x.Fee*1.21m,
                                                      Order = x.TransactionId,
                                                      Frequency = 30
                                                  })
                                          .GetEnumerator();
        }

        IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); }

        public void Get(object identifier) { throw new NotImplementedException(); }
        public void Save(RedsysRecurringTransaction item) { throw new NotImplementedException(); }

        public void Update(RedsysRecurringTransaction item)
        {
            Subscription subscription = _subscriptionRepository.Single(x => x.TransactionId == item.Order);
            subscription.EndDate = item.EndDate;
            subscription.StartDate = item.StartDate;
            subscription.Fee = item.Amount/1.21m;
            subscription.Frequency = UnitOfTime.Month;

            _subscriptionRepository.Update(subscription);
        }

        public void Delete(RedsysRecurringTransaction item) { throw new NotImplementedException(); }
    }

Last edited Nov 6, 2013 at 11:27 AM by zerosofadown, version 1