Ejemplo n.º 1
0
        public async Task <IActionResult> Create(long id, [FromForm] Growth growth)
        {
            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)
            {
                growth.GrowthId = default;
                growth.Infant   = default;
                context.Growths.Add(growth);
                await context.SaveChangesAsync();

                return(RedirectToAction("Index", "Dashboard", new { id = growth.InfantId }));
            }
            return(View("GrowthEditor", GrowthViewModelFactory.Create(growth, preSaveInfant)));
        }
Ejemplo n.º 2
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)));
        }
Ejemplo n.º 3
0
        // HTTP GEt
        public async Task <IActionResult> Delete(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.Delete(growth, growth.Infant)));
        }
Ejemplo n.º 4
0
        // 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"));
            }
            Growth growth = new Growth
            {
                Date     = DateTime.Now,
                InfantId = id
            };

            return(View("GrowthEditor", GrowthViewModelFactory.Create(growth, infant)));
        }