// HTTP Get public async Task <IActionResult> Edit(long id) { if (!IsLoggedIn()) { return(RedirectToPage("/Account/Login")); } Feeding feeding = await context.Feedings.Include(f => f.Infant).FirstOrDefaultAsync(f => f.FeedingId == id); if (!IsFeedingOwner(feeding)) { return(RedirectToPage("/Error/Error404")); } return(View("FeedingEditor", FeedingViewModelFactory.Edit(feeding, feeding.Infant))); }
public async Task <IActionResult> Edit(long id, [FromForm] Feeding feeding) { if (!IsLoggedIn()) { return(RedirectToPage("/Account/Login")); } Feeding preSaveFeeding = await context.Feedings.AsNoTracking().Include(f => f.Infant).FirstOrDefaultAsync(f => f.FeedingId == id); if (!IsFeedingOwner(preSaveFeeding)) { return(RedirectToPage("/Error/Error404")); } if (ModelState.IsValid) { context.Feedings.Update(feeding); await context.SaveChangesAsync(); return(RedirectToAction("Index", "Dashboard", new { id = feeding.InfantId })); } return(View("FeedingEditor", FeedingViewModelFactory.Edit(feeding, preSaveFeeding.Infant))); }