Esempio n. 1
0
        public bool CreateSleep(SleepCreate model)
        {
            var entity =
                new Sleep()
            {
                OwnerId    = _userId,
                HoursSlept = model.HoursSlept,
                WakeUpTime = model.WakeUpTime,
                Date       = model.Date,
                PersonId   = model.PersonId
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Sleeps.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
Esempio n. 2
0
        public bool CreateSleep(SleepCreate model)
        {
            var entity =
                new Sleep()
            {
                ParentID   = _userID,
                BabyID     = model.BabyID,
                Location   = model.Location,
                SleepStart = model.SleepStart,
                SleepEnd   = model.SleepEnd,
                Notes      = model.Notes,
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Sleeps.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
Esempio n. 3
0
        public ActionResult Create()
        {
            var babyService = CreateBabyService();
            var babies      = babyService.GetBaby()
                              .Select(x => new
            {
                Text  = x.Name,
                Value = x.BabyID
            });

            var model = new SleepCreate()
            {
                SleepStart = DateTime.Now,
                SleepEnd   = DateTime.Now,
                Babies     = new SelectList(babies, "Value", "Text")
            };

            return(View(model));
        }
Esempio n. 4
0
        public ActionResult Create(SleepCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var service = CreateSleepService();

            if (service.CreateSleep(model))
            {
                TempData["SaveResult"] = "Your baby's sleep data has been added!";
                return(RedirectToAction("Index"));
            }
            ;

            ModelState.AddModelError("", "Your baby's sleep data could not be added. Please, try again.");

            return(View(model));
        }
        public ActionResult Create(SleepCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var service = CreateSleepService();

            if (service.CreateSleep(model))
            {
                TempData["SaveResult"] = "Your entry was created.";
                return(RedirectToAction("Index"));
            }
            ;

            ModelState.AddModelError("", "Entry could not be created.");

            ViewBag.PersonId = new SelectList(_db.Persons, "PersonId", "Name", model.PersonId);

            return(View(model));
        }