public ActionResult Edit(int id)
        {
            var service = CreateDomFamilyService();
            var detail  = service.GetDomFamilyById(id);
            var model   =
                new DomFamilyEdit
            {
                DomFamId        = detail.DomFamId,
                Parent1Name     = detail.Parent1Name,
                Parent2Name     = detail.Parent2Name,
                IsHomeStudyDone = detail.IsHomeStudyDone
            };

            return(View(model));
        }
Пример #2
0
        public bool UpdateDomFamily(DomFamilyEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .DomFamilies
                    .Single(e => e.DomFamId == model.DomFamId && e.OwnerId == _userId);

                entity.Parent1Name     = model.Parent1Name;
                entity.Parent2Name     = model.Parent2Name;
                entity.PhoneNumber     = model.PhoneNumber;
                entity.Email           = model.Email;
                entity.IsHomeStudyDone = model.IsHomeStudyDone;
                entity.HomeStudyDate   = model.HomeStudyDate;

                return(ctx.SaveChanges() == 1);
            }
        }
        public ActionResult Edit(int id, DomFamilyEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (model.DomFamId != id)
            {
                ModelState.AddModelError("", "Id mismatch");
                return(View(model));
            }
            var service = CreateDomFamilyService();

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

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