Successive 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(); }
    }

Last edited Nov 6, 2013 at 12:22 PM by zerosofadown, version 2