public void Modify(PaymentPlanEntry entry)
        {
            context.Entry(entry).State = System.Data.EntityState.Modified;

            // Clean up, if necessary
            if (entry.Charges.Count < 1)
                Delete(entry);
        }
        private void UpdatePaymentPlans(CreditEntry entry)
        {
            // Is this a new payment plan charge we're adding?
            bool newAdd = true;
            PaymentPlanCharge charge;
            PaymentPlanEntry oldPlan = null;

            // Pull the charge for the DB.
            // If charge exists, pull the attached PaymentPlan
            // If charge does not exist, create a new charge
            charge = mUnitOfWork.PaymentPlanChargeRepo.PaymentPlanCharges
                .Where(c => c.CreditEntry.CreditEntryId == entry.CreditEntryId)
                .SingleOrDefault();

            if (charge != null)
            {
                oldPlan = charge.PaymentPlanEntry;
                newAdd = false;
            }
            else
            {
                charge = new PaymentPlanCharge
                    {
                        PurchaseAmount = entry.PurchaseTotal,
                        Description = entry.Description,
                        Comment = "Added" + DateTime.Now.ToShortDateString(),
                        CreditEntry = entry
                    };
            }

            // Does a paymentplan with the modified date already exist
            PaymentPlanEntry plan = mUnitOfWork.PaymentPlanRepo.PaymentPlanEntries
                .Where(p => p.PaymentDate == entry.PayDate.Value)
                .SingleOrDefault();

            if (plan != null)
            {
                plan.Charges.Add(charge);
                mUnitOfWork.PaymentPlanRepo.Modify(plan);
            }
            else
            {
                PaymentPlanEntry newEntry = new PaymentPlanEntry
                {
                    Card = entry.Card,
                    Charges = new List<PaymentPlanCharge> { charge },
                    PaymentDate = entry.PayDate.Value,
                    PaymentTotal = entry.AmountPaid,
                    ResponsibleParty = entry.ResponsibleParty

                };
                mUnitOfWork.PaymentPlanRepo.Add(newEntry);
            }

            // If this is an existing charge, remove from old PaymentPlan
            if (!newAdd)
            {
                oldPlan.Charges.Remove(charge);
                mUnitOfWork.PaymentPlanRepo.Modify(oldPlan);
            }
        }
 public void Delete(PaymentPlanEntry entry)
 {
     context.PaymentPlanEntries.Remove(entry);
 }
 public void Add(PaymentPlanEntry entry)
 {
     context.PaymentPlanEntries.Add(entry);
 }