public async Task<ActionResult> Edit(HouseholdView householdView, int? id) { if (id == null) return Json(new { result = "Failure" }); Household household = await GetDb().Households.FindAsync(id.GetValueOrDefault()); string userId = DEBUG ? USER_ID_DEBUG : User.Identity.GetUserId(); if (household == null || !household.HasMemberById(userId)) return Json(new { result = "Failure" }); household.Name = householdView.Name; await GetDb().SaveChangesAsync(); return Json(new { result = "Success" }); }
public async Task<ActionResult> Create(HouseholdView householdView) { if (ModelState.IsValid) { Household household = new Household(); household.Name = householdView.Name; household = GetDb().Households.Add(household); UserHousehold userHousehold = new UserHousehold(); userHousehold.UserID = DEBUG ? USER_ID_DEBUG : User.Identity.GetUserId(); household.UserHouseholds.Add(userHousehold); await GetDb().SaveChangesAsync(); return Json(new { result = "Success" }); } return Json(new { result = "Failed" }); }