public async Task<ActionResult> Create(int? id) { if (id == null) return HttpNotFound(); Household household = await GetDb().Households.FindAsync(id); if (household == null || !household.HasMemberById(User.Identity.GetUserId())) return HttpNotFound(); ViewBag.Title = "Add an account to " + household.Name; AddAccountView addAccountView = new AddAccountView(); this.AddTemp(addAccountView, "HouseholdID", id.GetValueOrDefault()); return PartialView("_AddAccountPartial", addAccountView); }
public async Task<ActionResult> Create(AddAccountView addAccountView) { if (ModelState.IsValid) { Account account = new Account(); account.Name = addAccountView.Name; account.ReconciledBalance = addAccountView.Balance; account.HouseholdID = this.GetTemp<int>(addAccountView, "HouseholdID"); GetDb().Accounts.Add(account); await GetDb().SaveChangesAsync(); return Json(new { result = "Success" }); } return Json(new { result = "Failed" }); }