Exemplo n.º 1
0
 // GET: /Administration/Laptops/Create
 public ActionResult Create()
 {
     LaptopCreateViewModel vm = new LaptopCreateViewModel
     {
         Manufacturers = db.Manufacturers.All().ToList()
     };
     return View(vm);
 }
Exemplo n.º 2
0
        public ActionResult Create(LaptopCreateViewModel postedLaptop, string manufacturer)
        {
            if (ModelState.IsValid)
            {
                var laptop = postedLaptop.Laptop;
                laptop.Manufacturer = db.Manufacturers.All().Single(x => x.Name == manufacturer);


                db.Laptops.Add(laptop);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            postedLaptop.Manufacturers = db.Manufacturers.All().ToList();

            return View(postedLaptop);
        }