示例#1
0
        public CreditEntryWrapper(CreditEntry entry, UnitofWork unitOfWork, IEnumerable<CardEntry> cards, IEnumerable<PartyEntry> parties)
        {
            this.mEntry = entry;
            this.mUnitOfWork = unitOfWork;

            if (cards != null) mCards = cards;
            if (parties != null) mParties = parties;
        }
示例#2
0
        private void DeleteCharges(CreditEntry entry)
        {
            // Find existing charge and the PaymentPlan it's attached to
            PaymentPlanCharge charge = mUnitOfWork.PaymentPlanChargeRepo.PaymentPlanCharges
                .Where(c => c.CreditEntry == entry)
                .First();

            PaymentPlanEntry oldPlan = charge.PaymentPlanEntry;

            // Remove charge from payment plan.  Then remove charge.
            oldPlan.Charges.Remove(charge);
            mUnitOfWork.PaymentPlanChargeRepo.Delete(charge);
        }
示例#3
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);
            }
        }
示例#4
0
        public ActionResult Edit(CreditEntry Entry, bool add)
        {
            //string card = unitOfWork.CardRepo.CreditCards.Where(c => c.Card == Request.Params.Get("Card"));
            string card = Request.Params.Get("Card");
            CardEntry cardEntry = unitOfWork.CardRepo.CreditCards
                                    .Where(c => c.Card == card)
                                    .FirstOrDefault();
            Entry.Card = cardEntry;

            string party = Request.Params.Get("ResponsibleParty");
            PartyEntry partyEntry = unitOfWork.PartyRepo.Parties
                                    .Where(p => p.PartyName == party)
                                    .FirstOrDefault();
            Entry.ResponsibleParty = partyEntry;

            ModelState.SetModelValue("Card", new ValueProviderResult(cardEntry, card, System.Globalization.CultureInfo.InvariantCulture));

            if (ModelState.IsValid)
            {
                Entry.AmountRemaining = Entry.PurchaseTotal - Entry.AmountPaid;

                if (add)
                    unitOfWork.CreditRepo.Add(Entry);
                else
                    unitOfWork.CreditRepo.Edit(Entry);

                unitOfWork.Save();
                return RedirectToAction("List");
            }
            else
            {
                return View();
            }
        }
示例#5
0
        public ActionResult Edit(int? EntryID)
        {
            CreditEntry Entry;

            // If EntryID is null, we are adding
            if (EntryID == null)
            {
                Entry = new CreditEntry();
                ViewBag.Action = true;
            }
            else
            {
                Entry = (CreditEntry)CreditEntryList.CreditEntries
                    .Where(m => m.CreditEntryId == EntryID)
                    .First();
                ViewBag.Action = false;
            }

            ViewBag.Cards = CardList.CreditCards;

            return View(Entry);
        }
示例#6
0
        public ActionResult Delete(CreditEntry Entry)
        {
            unitOfWork.CreditRepo.Delete(Entry);
            unitOfWork.Save();

            return RedirectToAction("List");
        }
示例#7
0
 public void Edit(CreditEntry Entry)
 {
     DbContext.Entry(Entry).State = System.Data.EntityState.Modified;
     //DbContext.SaveChanges();
 }
示例#8
0
 public void Delete(CreditEntry Entry)
 {
     DbContext.Entry(Entry).State = System.Data.EntityState.Deleted;
     //DbContext.SaveChanges();
 }