//GET: Household Dashboard public ActionResult Household() { var user = db.Users.Find(User.Identity.GetUserId()); var householdId = (int)user.HouseholdId; var viewData = new HouseholdVM { HouseholdId = householdId, HouseholdName = db.Households.Find(householdId).Name, UsersBankAccounts = new SelectList(db.BankAccounts.Where(ba => ba.OwnerId == user.Id && ba.HouseholdId != householdId).OrderBy(ba => ba.Name), "Id", "DisplayName"), Budgets = new SelectList(db.Categories.Where(c => c.HouseholdId == householdId).OrderBy(c => c.Name), "Id", "Name") }; ViewBag.BudgetCategories = db.CategoryItems.Where(ci => ci.Category.HouseholdId == householdId).Count(); return(View(viewData)); }
public async Task <ActionResult> CreateHousehold(HouseholdVM vm) { Household hh = new Household(); hh.Name = vm.HHName; db.Households.Add(hh); db.SaveChanges(); var user = db.Users.Find(User.Identity.GetUserId()); hh.Members.Add(user); db.SaveChanges(); await ControllerContext.HttpContext.RefreshAuthentication(user); return(RedirectToAction("Index", "Home")); }