public ActionResult Edit(int id)
        {
            var service = CreateWheelsService();
            var detail  = service.GetWheelsById(id);
            var model   =
                new WheelsEdit
            {
                WheelsID     = detail.WheelsID,
                WheelsName   = detail.WheelsName,
                WheelsColor  = detail.WheelsColor,
                WheelsRarity = detail.WheelsRarity,
            };

            return(View(model));
        }
示例#2
0
        public bool UpdateWheels(WheelsEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Wheelss
                    .Single(e => e.WheelsID == model.WheelsID && e.OwnerID == _userID);

                entity.WheelsID     = model.WheelsID;
                entity.WheelsName   = model.WheelsName;
                entity.WheelsColor  = model.WheelsColor;
                entity.WheelsRarity = model.WheelsRarity;

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

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

            var service = CreateWheelsService();

            if (service.UpdateWheels(model))
            {
                TempData["SaveResult"] = "Your wheels were updated.";
                return(RedirectToAction("Index"));
            }

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