예제 #1
0
        public ActionResult Edit(int id)
        {
            var service = CreateMotherService();
            var detail  = service.GetMotherById(id);
            var model   =
                new MotherEdit
            {
                MotherId       = detail.MotherId,
                FirstName      = detail.FirstName,
                LastName       = detail.LastName,
                MotherLocation = detail.MotherLocation,
                DueDate        = detail.DueDate,
                BreastFeeding  = detail.BreastFeeding
            };

            return(View(model));
        }
예제 #2
0
        public bool UpdateMother(MotherEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Mothers
                    .Single(e => e.MotherId == model.MotherId && e.OwnerId == _userId);

                entity.MotherId       = model.MotherId;
                entity.FirstName      = model.FirstName;
                entity.LastName       = model.LastName;
                entity.MotherLocation = model.MotherLocation;
                entity.DueDate        = model.DueDate;
                entity.BreastFeeding  = model.BreastFeeding;

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

            if (model.MotherId != id)
            {
                ModelState.AddModelError("", "ID Mismatch");
                return(View(model));
            }

            var service = CreateMotherService();

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

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