public async Task <IActionResult> Create(long id, [FromForm] Diaper diaper)
        {
            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)
            {
                diaper.DiaperId = default;
                diaper.Infant   = default;
                context.Diapers.Add(diaper);
                await context.SaveChangesAsync();

                return(RedirectToAction("Index", "Dashboard", new { id = diaper.InfantId }));
            }
            return(View("DiaperEditor", DiaperViewModelFactory.Create(diaper, preSaveInfant)));
        }
Beispiel #2
0
        public async Task <IActionResult> Create([Bind("UserID,Username")] Users users)
        {
            if (ModelState.IsValid)
            {
                _context.Add(users);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(users));
        }
        public async Task <IActionResult> Create([Bind("DiaperChangeID,NumberofDiaperChanges,Date,BabyName")] DiaperChange diaperChange)
        {
            if (ModelState.IsValid)
            {
                _context.Add(diaperChange);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BabyName"] = new SelectList(_context.BabyInfo, "BabyName", "BabyName", diaperChange.BabyName);
            return(View(diaperChange));
        }
        public async Task <IActionResult> Create([Bind("FeedingID,NumberOfFeedings,FeedingTime,BabyName")] Feeding feeding)
        {
            if (ModelState.IsValid)
            {
                _context.Add(feeding);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BabyName"] = new SelectList(_context.BabyInfo, "BabyName", "BabyName", feeding.BabyName);
            return(View(feeding));
        }
        public async Task <IActionResult> Create([Bind("BabyName,BabyGender,BirthDate,UserID")] BabyInfo babyInfo)
        {
            if (ModelState.IsValid)
            {
                _context.Add(babyInfo);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["UserID"] = new SelectList(_context.Users, "UserID", "UserID", babyInfo.UserID);
            return(View(babyInfo));
        }
Beispiel #6
0
        public async Task <IActionResult> Create([Bind("MileStoneID,EventDate,Details,BabyName")] BabyMileStone babyMileStone)
        {
            if (ModelState.IsValid)
            {
                _context.Add(babyMileStone);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BabyName"] = new SelectList(_context.BabyInfo, "BabyName", "BabyName", babyMileStone.BabyName);
            return(View(babyMileStone));
        }
Beispiel #7
0
        public async Task <IActionResult> Create([FromForm] Infant infant)
        {
            if (!IsLoggedIn())
            {
                return(RedirectToPage("/Account/Login"));
            }
            if (ModelState.IsValid)
            {
                infant.InfantId = default;
                context.Infants.Add(infant);
                await context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View("InfantEditor", InfantViewModelFactory.Create(infant)));
        }
Beispiel #8
0
        public async Task <IActionResult> Create(long id, [FromForm] Sleep sleep)
        {
            if (!IsLoggedIn())
            {
                return(RedirectToPage("/Account/Login"));
            }
            Infant preSaveInfant = context.Infants.FirstOrDefault(i => i.InfantId == id);

            if (!IsInfantOwner(preSaveInfant))
            {
                return(RedirectToPage("/Error/Error404"));
            }
            if (ModelState.IsValid)
            {
                sleep.SleepId = default;
                sleep.Infant  = default;
                context.Sleeps.Add(sleep);
                await context.SaveChangesAsync();

                return(RedirectToAction("Index", "Dashboard", new { id = sleep.InfantId }));
            }
            return(View("SleepEditor", SleepViewModelFactory.Create(sleep, preSaveInfant)));
        }