コード例 #1
0
        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)));
        }
コード例 #2
0
        // 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)));
        }