public ActionResult Edit([Bind(Include = "Id,Name,Description,AllocationType,Amount,AccountId,Notes,DestinationAccountId")] SavingsInvestment savingsInvestment,
                                 [Bind(Include = "RecurrenceFrequencyEnum, RecuranceStartDate, RecuranceEndDate, RecuranceDayNumber")] Recurrence recurrence)
        {
            if (ModelState.IsValid)
            {
                Allocation targetSI = db.Allocations.Find(savingsInvestment.Id);
                if (targetSI.Recurrence == null)
                {
                    db.Recurrences.AddOrUpdate(recurrence);
                    db.SaveChanges();
                    savingsInvestment.RecurrenceId = recurrence.Id;
                }
                else
                {
                    recurrence.Id = targetSI.Recurrence.Id;
                    savingsInvestment.RecurrenceId = targetSI.RecurrenceId;
                    db.Recurrences.AddOrUpdate(recurrence);
                }

                db.Allocations.AddOrUpdate(savingsInvestment);
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }
            ViewBag.AccountId            = new SelectList(db.Accounts, "Id", "Name", savingsInvestment.AccountId);
            ViewBag.DestinationAccountId = new SelectList(db.Accounts, "Id", "Name", savingsInvestment.DestinationAccountId).OrderBy(x => x.Text);
            return(View(savingsInvestment));
        }
        // GET: SavingsInvestments/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            SavingsInvestment savingsInvestment = (SavingsInvestment)db.Allocations.Find(id);

            if (savingsInvestment == null)
            {
                return(HttpNotFound());
            }
            return(View(savingsInvestment));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            SavingsInvestment savingsInvestment = (SavingsInvestment)db.Allocations.Find(id);

            if (savingsInvestment.Recurrence != null)
            {
                var recurrence = db.Recurrences.Find(savingsInvestment.RecurrenceId);
                db.Recurrences.Remove(recurrence);
            }
            db.Allocations.Remove(savingsInvestment);

            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        // GET: SavingsInvestments/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            SavingsInvestment savingsInvestment = (SavingsInvestment)db.Allocations.Find(id);

            if (savingsInvestment == null)
            {
                return(HttpNotFound());
            }
            ViewBag.AccountId            = new SelectList(db.Accounts, "Id", "Name", savingsInvestment.AccountId);
            ViewBag.DestinationAccountId = new SelectList(db.Accounts, "Id", "Name", savingsInvestment.DestinationAccountId);
            return(View(savingsInvestment));
        }