protected PrimaryIncome GetPrimaryIncome() { PrimaryIncome primaryIncome = db.PrimaryIncome.Where(x => x.User.Id == user.Id).Include(x => x.Income).FirstOrDefault(); if (primaryIncome == null) { return(new PrimaryIncome { User = user }); } primaryIncome.Income = primaryIncome.Income.Populate(user); return(primaryIncome); }
public ActionResult ChoosePrimaryIncome(int?incomeId) { ViewBag.Action = "Choose Primary Income"; PrimaryIncome primaryIncome = GetPrimaryIncome(); if (ModelState.IsValid && incomeId != null) { bool newEntry = (primaryIncome.ID == 0); primaryIncome.Income = db.Incomes.Find(incomeId); primaryIncome.User = db.Users.Find(user.Id); if (newEntry) { db.PrimaryIncome.Add(primaryIncome); } else { db.Entry(primaryIncome).State = EntityState.Modified; } db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Incomes = GetIncomes(false); return(View(GetPrimaryIncome())); }