public ActionResult Create(GearCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (service.CreateGear(model))
            {
                TempData["SaveResults"] = "Gear Created Successfully!";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Could not create Gear.");
            return(View(model));
        }
Example #2
0
        public bool CreateGear(GearCreate model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity = new Gear()
                {
                    Name         = model.Name,
                    Price        = model.Price,
                    NumAvailable = model.NumAvailable,
                    CategoryId   = model.CategoryId,
                    PictureUrl   = model.PictureUrl
                };

                ctx.Gear.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }