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