/// <summary>
 /// Assigns the donation batch to approved donations
 /// </summary>
 /// <param name="batch">Batch donation details</param>
 public void AssignBatchToApprovedDonations(PaymentToOrganisationBatch batch)
 {
     using (var db = new GenerousAPIEntities())
     {
         db.AssignBatchToApprovedDonations(batch.Id);
     }
 }
        /// <summary>
        /// Create a payment batch for an organisatsion
        /// </summary>
        /// <param name="batch">Payment batch details</param>
        public void CreatePaymentToOrganisationBatch(PaymentToOrganisationBatch batch)
        {
            using (var db = new GenerousAPIEntities())
            {
                using (var trans = db.Database.BeginTransaction())
                {
                    try
                    {
                        db.PaymentToOrganisationBatches.Add(batch);

                        if (batch.PaymentToOrganisationBatchLineItems != null && batch.PaymentToOrganisationBatchLineItems.Count > 0)
                        {
                            db.PaymentToOrganisationBatchLineItems.AddRange(batch.PaymentToOrganisationBatchLineItems);
                        }

                        db.SaveChanges();

                        trans.Commit();
                    }
                    catch (Exception ex)
                    {
                        trans.Rollback();
                        throw ex;
                    }
                }
            }
        }
 /// <summary>
 /// Update batch payment details
 /// </summary>
 /// <param name="batch">Batch details</param>
 /// <param name="updatedOn">Date/time batch updated</param>
 /// <param name="updatedBy">Who pdated batch</param>
 public void UpdatePaymentToOrganisationBatchProcessStatus(PaymentToOrganisationBatch batch, DateTime updatedOn, string updatedBy)
 {
     using (var db = new GenerousAPIEntities())
     {
         db.UpdatePaymentToOrganisationBatchProcessStatus(batch.Id, updatedOn, updatedBy);
     }
 }
        /// <summary>
        /// Get a collection of of transactions associated with the batch id
        /// </summary>
        /// <param name="batch">Batch ID</param>
        /// <returns>Donations in the batch</returns>
        public IEnumerable <TransactionDetail> GetDonationTransactionsAssignedToBatch(PaymentToOrganisationBatch batch)
        {
            using (var db = new GenerousAPIEntities())
            {
                var query = from t in db.TransactionDetails
                            where t.PaymentToOrganisationBatchId == batch.Id
                            select t;

                return(query.ToList <TransactionDetail>());
            }
        }
        /// <summary>
        /// Get collection of batch items to process
        /// </summary>
        /// <param name="batch">Batch items</param>
        /// <param name="dateTimeToBeProcessed">Process date time</param>
        /// <returns>Collection of batch items to process</returns>
        public IEnumerable <PaymentToOrganisationBatchLineItem> GetPaymentToOrganisationBatchLineItems_ForProcessing(PaymentToOrganisationBatch batch, DateTime dateTimeToBeProcessed)
        {
            using (var db = new GenerousAPIEntities())
            {
                var lineItemList = from lineItem in db.PaymentToOrganisationBatchLineItems
                                   where
                                   lineItem.BatchId == batch.Id &&
                                   lineItem.ProcessDateTime <= dateTimeToBeProcessed &&
                                   lineItem.DoNotProcess == false
                                   select lineItem;

                return(lineItemList.ToList <PaymentToOrganisationBatchLineItem>());
            }
        }