// HTTP GET public async Task <IActionResult> Edit(long id) { if (!IsLoggedIn()) { return(RedirectToPage("/Account/Login")); } Infant infant = await context.Infants.FindAsync(id); if (!IsInfantOwner(infant)) { return(RedirectToPage("/Error/Error404")); } InfantViewModel model = InfantViewModelFactory.Edit(infant); return(View("InfantEditor", model)); }
public async Task <IActionResult> Edit(long id, [FromForm] Infant infant) { if (!IsLoggedIn()) { return(RedirectToPage("/Account/Login")); } Infant preSaveInfant = await context.Infants.AsNoTracking().FirstOrDefaultAsync(i => i.InfantId == id); if (!IsInfantOwner(preSaveInfant)) { return(RedirectToPage("/Error/Error404")); } if (ModelState.IsValid) { context.Infants.Update(infant); await context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View("InfantEditor", InfantViewModelFactory.Edit(infant))); }