// GET: Gear/Edit/{id}
        public ActionResult Edit(int id)
        {
            var detail = service.GetGearById(id);
            var model  = new GearEdit()
            {
                GearId       = detail.GearId,
                Name         = detail.Name,
                Price        = detail.Price,
                NumAvailable = detail.NumAvailable,
                CategoryId   = detail.Category.CategoryId,
                PictureUrl   = detail.PictureUrl
            };

            return(View(model));
        }
Exemple #2
0
        public bool UpdateGear(GearEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity = ctx.Gear.Find(model.GearId);

                entity.Name         = model.Name;
                entity.Price        = model.Price;
                entity.NumAvailable = model.NumAvailable;
                entity.CategoryId   = model.CategoryId;
                entity.PictureUrl   = model.PictureUrl;

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

            if (id != model.GearId)
            {
                ModelState.AddModelError("", "IDs do not match.");
                return(View(model));
            }

            if (service.UpdateGear(model))
            {
                TempData["SaveResult"] = "Gear Updated Successfully!";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Gear was not able to update.");
            return(View(model));
        }