public async Task <IActionResult> Edit(long id, [FromForm] Growth growth) { if (!IsLoggedIn()) { return(RedirectToPage("/Account/Login")); } Growth preSaveGrowth = await context.Growths.AsNoTracking().Include(g => g.Infant).FirstOrDefaultAsync(g => g.GrowthId == id); if (!IsGrowthOwner(preSaveGrowth)) { return(RedirectToPage("/Error/Error404")); } Infant infant = preSaveGrowth.Infant; if (ModelState.IsValid) { context.Growths.Update(growth); await context.SaveChangesAsync(); return(RedirectToAction("Index", "Dashboard", new { id = growth.InfantId })); } return(View("GrowthEditor", GrowthViewModelFactory.Edit(growth, infant))); }
// HTTP Get public async Task <IActionResult> Edit(long id) { if (!IsLoggedIn()) { return(RedirectToPage("/Account/Login")); } Growth growth = await context.Growths.Include(g => g.Infant).FirstOrDefaultAsync(g => g.GrowthId == id); if (!IsGrowthOwner(growth)) { return(RedirectToPage("/Error/Error404")); } return(View("GrowthEditor", GrowthViewModelFactory.Edit(growth, growth.Infant))); }