public async Task <IActionResult> Edit(int id, ChoresEditViewModel model) { if (ModelState.IsValid) { _context.Update(model.Chore); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["DayId"] = new SelectList(_context.Day, "DayId", "DayName", new { id = model.Chore.ChoreId }); return(View(model)); }
// GET: Chores/Edit/5 public async Task <IActionResult> Edit(int?id) { var user = await GetCurrentUserAsync(); //setting condition if there is no ID or no ID match to databse, return Not found from the null response if (id == null) { return(NotFound()); } //the response from the async (await) for the context(what is grabbing properties) for chore ad finidng the id that is binded var chore = await _context.Chore .FindAsync(id); // if the property of chore returns null throw a NotFound message if (chore == null) { return(NotFound()); } // using the viewmodel variable from ChoresEditViewModel, create a new instance from the context method ChoresEditViewModel viewmodel = new ChoresEditViewModel(_context) { //This addidtion lets us use theIsParent on Edit View IsParent = user.IsParent, } ; //using the viewmodel variable's property chore(as an object), define it as chore. This will let us use the information from the created chore to display viewmodel.Chore = chore ; viewmodel.FamilyId = user.FamilyId; var family = await _context.Family .Include(u => u.Users) .SingleOrDefaultAsync(fam => fam.FamilyId == viewmodel.FamilyId); viewmodel.Family = family; //return the viewmodel variable with new information return(View(viewmodel));; }