Exemple #1
0
        public bool UpdateFosterHome(FosterHomeEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Homes
                    .Single(e => e.HomeId == model.HomeId);

                entity.HomeId            = model.HomeId;
                entity.FamilyName        = model.FamilyName;
                entity.OpenBeds          = model.OpenBeds;
                entity.GenderPref        = model.GenderPref;
                entity.AgePrefMin        = model.AgePrefMin;
                entity.AgePrefMax        = model.AgePrefMax;
                entity.SchoolDistrict    = model.SchoolDistrict;
                entity.Agency            = model.Agency;
                entity.CaseworkerName    = model.CaseworkerName;
                entity.CaseworkerContact = model.CaseworkerContact;
                entity.Comments          = model.Comments;
                entity.PhotoUrl          = model.PhotoUrl;
                entity.ModifiedUtc       = model.ModifiedUtc;

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

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

            var service = CreateFosterHomeService();

            if (service.UpdateFosterHome(model))
            {
                TempData["SaveResult"] = "The Foster Home was updated.";
                return(RedirectToAction("Index"));
            }
            ModelState.AddModelError("", "The Foster Home could not be updated.");
            return(View());
        }
        public ActionResult Edit(int id)
        {
            var service = CreateFosterHomeService();
            var detail  = service.GetHomeById(id);
            var model   =
                new FosterHomeEdit
            {
                HomeId            = detail.HomeId,
                FamilyName        = detail.FamilyName,
                OpenBeds          = detail.OpenBeds,
                GenderPref        = detail.GenderPref,
                AgePrefMin        = detail.AgePrefMin,
                AgePrefMax        = detail.AgePrefMax,
                SchoolDistrict    = detail.SchoolDistrict,
                Agency            = detail.Agency,
                CaseworkerName    = detail.CaseworkerName,
                CaseworkerContact = detail.CaseworkerContact,
                Comments          = detail.Comments,
                PhotoUrl          = detail.PhotoUrl
            };

            return(View(model));
        }