Exemplo n.º 1
0
        public ActionResult Edit(int id)
        {
            var service = CreateHomeStudyService();
            var detail  = service.GetHomeStudyById(id);
            var model   =
                new HomeStudyEdit
            {
                HomeStudyId     = detail.HomeStudyId,
                Parent1Name     = detail.Parent1Name,
                Parent2Name     = detail.Parent2Name,
                TypeOfHomeStudy = detail.TypeOfHomeStudy,
                Agency          = detail.Agency
            };

            return(View(model));
        }
        public bool UpdateHomeStudy(HomeStudyEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .HomeStudies
                    .Single(e => e.HomeStudyId == model.HomeStudyId && e.OwnerId == _userId);

                entity.Parent1Name     = model.Parent1Name;
                entity.Parent2Name     = model.Parent2Name;
                entity.PhoneNumber     = model.PhoneNumber;
                entity.Email           = model.Email;
                entity.TypeOfHomeStudy = model.TypeOfHomeStudy;
                entity.Agency          = model.Agency;


                return(ctx.SaveChanges() == 1);
            }
        }
Exemplo n.º 3
0
        public ActionResult Edit(int id, HomeStudyEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            if (model.HomeStudyId != id)
            {
                ModelState.AddModelError("", "Id Mismatch");
                return(View(model));
            }

            var service = CreateHomeStudyService();

            if (service.UpdateHomeStudy(model))
            {
                TempData["SaveResult"] = "Your family was updated.";
                return(RedirectToAction("Index"));
            }

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