// HTTP GEt public async Task <IActionResult> Delete(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.Delete(feeding, feeding.Infant))); }
// HTTP Get public IActionResult Create(long id) { if (!IsLoggedIn()) { return(RedirectToPage("/Account/Login")); } Infant infant = context.Infants.FirstOrDefault(i => i.InfantId == id); if (!IsInfantOwner(infant)) { return(RedirectToPage("/Error/Error404")); } Feeding feeding = new Feeding { StartTime = DateTime.Now, InfantId = id }; return(View("FeedingEditor", FeedingViewModelFactory.Create(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))); }
public async Task <IActionResult> Create(long id, [FromForm] Feeding feeding) { if (!IsLoggedIn()) { return(RedirectToPage("/Account/Login")); } Infant preSaveInfant = context.Infants.AsNoTracking().FirstOrDefault(i => i.InfantId == id); if (!IsInfantOwner(preSaveInfant)) { return(RedirectToPage("/Error/Error404")); } if (ModelState.IsValid) { feeding.FeedingId = default; feeding.Infant = default; context.Feedings.Add(feeding); await context.SaveChangesAsync(); return(RedirectToAction("Index", "Dashboard", new { id = feeding.InfantId })); } return(View("FeedingEditor", FeedingViewModelFactory.Create(feeding, preSaveInfant))); }