示例#1
0
        // GET : Nursing Data
        public ActionResult Edit(int id)
        {
            var service     = CreateNursingService();
            var babyService = CreateBabyService();
            var detail      = service.GetNursingDataById(id);
            var babies      = babyService.GetBaby()
                              .Select(x => new
            {
                Text  = x.Name,
                Value = x.BabyID
            });
            var model =
                new NursingEdit
            {
                NursingID   = detail.NursingID,
                Time        = detail.Time,
                TimeFed     = detail.TimeFed,
                Name        = detail.Name,
                FeedingSide = detail.FeedingSide,
                Notes       = detail.Notes,
                Babies      = new SelectList(babies, "Value", "Text"),
                BabyID      = detail.BabyID
            };

            return(View(model));
        }
示例#2
0
        public bool UpdateNursingData(NursingEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Nursings
                    .Single(e => e.ID == model.NursingID && e.ParentID == _userID);
                entity.Time        = model.Time;
                entity.TimeFed     = model.TimeFed;
                entity.Name        = model.Name;
                entity.FeedingSide = model.FeedingSide;
                entity.Notes       = model.Notes;
                entity.BabyID      = model.BabyID;


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

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

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

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