public ActionResult Create(Laptop laptop)
        {
            if (ModelState.IsValid)
            {
                db.Laptops.Add(laptop);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.ManufacturerId = new SelectList(db.Manufacturers, "Id", "Name", laptop.ManufacturerId);
            return View(laptop);
        }
        public void Add_Should_Return_DbEntityValidationException_For_Model()
        {
            var laptop = new Laptop
            {
                Model = null,
                HardDiskSize = 500,
                ImageUrl = @"~/images/laptopImage.jpg",
                MonitorSize = 15.6,
                Price = 1600,
                RamMemorySize = 6,
                ManufacturerId = 2
            };

            this.data.Laptops.Add(laptop);
            this.data.SaveChanges();
        }
        public void GetById_Should_Return_Selected_Laptops()
        {
            var laptop = new Laptop
            {
                HardDiskSize = 500,
                ImageUrl = @"~/images/laptopImage.jpg",
                Model = "EliteBook 8760w",
                MonitorSize = 15.6,
                Price = 1600,
                RamMemorySize = 6,
                ManufacturerId = 2
            };

            this.data.Laptops.Add(laptop);
            this.data.SaveChanges();

            var expected = this.data.Laptops.GetById(laptop.Id);

            Assert.AreSame(expected, laptop, "Laptop's repository GetById method returns different laptop than expected.");
        }
예제 #4
0
 public ActionResult Edit(Laptop laptop)
 {
     if (ModelState.IsValid)
     {
         db.Laptops.Update(laptop);
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(laptop);
 }
 public ActionResult Edit(Laptop laptop)
 {
     if (ModelState.IsValid)
     {
         db.Entry(laptop).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     ViewBag.ManufacturerId = new SelectList(db.Manufacturers, "Id", "Name", laptop.ManufacturerId);
     return View(laptop);
 }