Beispiel #1
0
        public ActionResult Edit(int id)
        {
            var service = CreateCenterService();
            var detail  = service.GetCenterById(id);
            var model   =
                new CenterEdit
            {
                CenterId = detail.CenterId,
                Name     = detail.Name,
                City     = detail.City,
                State    = detail.State
            };

            return(View(model));
        }
Beispiel #2
0
        public bool UpdateCenter(CenterEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Centers
                    .Single(e => e.CenterId == model.CenterId);
                entity.Name    = model.Name;
                entity.City    = model.City;
                entity.State   = model.State;
                entity.Country = model.Country;

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

            if (model.CenterId != id)
            {
                ModelState.AddModelError("", "Id Mismatch");
                return(View(model));
            }
            var service = CreateCenterService();

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

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