Beispiel #1
0
        public ActionResult Create(BottleCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var service     = CreateBottleService();
            var babyService = CreateBabyService();
            var babies      = babyService.GetBaby()
                              .Select(x => new
            {
                Text  = x.Name,
                Value = x.BabyID
            });

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

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

            return(View(model));
        }
Beispiel #2
0
        public ActionResult Create()
        {
            var babyService = CreateBabyService();
            var babies      = babyService.GetBaby()
                              .Select(x => new
            {
                Text  = x.Name,
                Value = x.BabyID
            });

            var model = new BottleCreate()
            {
                Babies = new SelectList(babies, "Value", "Text")
            };

            return(View(model));
        }
Beispiel #3
0
        public bool CreateBottle(BottleCreate model)
        {
            var entity =
                new BottleFeeding()
            {
                ParentID = _userID,
                BabyID   = model.BabyID,
                Name     = model.Name,
                Time     = model.Time,
                Contents = model.Contents,
                Quantity = model.Quantity,
                Consumed = model.Consumed,
                Notes    = model.Notes
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Bottles.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }