Ejemplo n.º 1
0
 public void Modify(PaymentPlanCharge entry)
 {
     context.Entry(entry).State = System.Data.EntityState.Modified;
     //context.SaveChanges();
 }
Ejemplo n.º 2
0
 public void Add(PaymentPlanCharge entry)
 {
     context.PaymentPlanCharges.Add(entry);
     //context.SaveChanges();
 }
Ejemplo n.º 3
0
 public void Delete(PaymentPlanCharge entry)
 {
     context.PaymentPlanCharges.Remove(entry);
     //context.SaveChanges();
 }
Ejemplo n.º 4
0
        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);
            }
        }