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
        // 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)));
        }