示例#1
0
        // GET : Bottle Details by ID
        public ActionResult Edit(int id)
        {
            var service     = CreateBottleService();
            var babyService = CreateBabyService();
            var detail      = service.GetBottleById(id);
            var babies      = babyService.GetBaby()
                              .Select(x => new
            {
                Text  = x.Name,
                Value = x.BabyID
            });

            var model =
                new BottleEdit
            {
                BabyID   = detail.BabyID,
                BottleID = detail.BottleID,
                Time     = detail.Time,
                Contents = detail.Contents,
                Quantity = detail.Quantity,
                Consumed = detail.Consumed,
                Notes    = detail.Notes,
                Babies   = new SelectList(babies, "Value", "Text")
            };

            return(View(model));
        }
示例#2
0
        public bool UpdateBottle(BottleEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Bottles
                    .Single(e => e.ID == model.BottleID && e.ParentID == _userID);
                entity.Time     = model.Time;
                entity.Contents = model.Contents;
                entity.Quantity = model.Quantity;
                entity.Consumed = model.Consumed;
                entity.Notes    = model.Notes;
                entity.BabyID   = model.BabyID;

                return(ctx.SaveChanges() == 1);
            }
        }
示例#3
0
        public ActionResult Edit(int id, BottleEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (model.BottleID != id)
            {
                ModelState.AddModelError("", "ID Mismatch");
                return(View(model));
            }
            var service = CreateBottleService();

            if (service.UpdateBottle(model))
            {
                TempData["SaveResult"] = "The bottle was updated.";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "The bottle could not be updated.");
            return(View());
        }