public ActionResult Edit(int id, MechanicalEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

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

            var service = CreateMechanicalService();

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

            ModelState.AddModelError("", "The information could not be updated.");

            return(View(model));
        }
示例#2
0
        public bool UpdateMechanical(MechanicalEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Mechanicals
                    .Single(e => e.MechId == model.MechId);

                entity.Address              = (string)model.Address;
                entity.ElecService          = model.ElecService;;
                entity.ElecServiceCondition = model.ElecServiceCondition;
                entity.ServicePanel         = model.ServicePanel;
                entity.PanelCondition       = model.PanelCondition;
                entity.Wiring          = model.Wiring;
                entity.WiringCondition = model.WiringCondition;
                entity.SwitchPlug      = model.SwitchPlug;
                entity.GFCPlug         = model.GFCPlug;
                entity.SmokeDetectors  = model.SmokeDetectors;



                return(ctx.SaveChanges() == 1);
            }
        }
        public ActionResult Edit(int id)
        {
            var service = CreateMechanicalService();
            var detail  = service.GetMechanicalById(id);

            var model =
                new MechanicalEdit
            {
                MechId               = detail.MechId,
                Address              = detail.Address,
                ElecService          = detail.ElecService,
                ElecServiceCondition = detail.ElecServiceCondition,
                ServicePanel         = detail.ServicePanel,
                PanelCondition       = detail.PanelCondition,
                Wiring               = detail.Wiring,
                WiringCondition      = detail.WiringCondition,
                SwitchPlug           = detail.SwitchPlug,
                GFCPlug              = detail.GFCPlug,
                SmokeDetectors       = detail.SmokeDetectors
            };

            return(View(model));
        }