コード例 #1
0
        public void RetailersController_Create_isNotValid()
        {
            Retailer testRetailer = new Retailer();
            testRetailer.retailerName = "invalidRetailer";
            RetailersController controller = new RetailersController();
            controller.ModelState.AddModelError("", "error message");

            var result = controller.Create(testRetailer) as ViewResult;
            Retailer resultRetailers = (Retailer)result.Model;

            Assert.AreEqual("invalidRetailer", resultRetailers.retailerName);
        }
コード例 #2
0
        public void RetailersController_Create_isValid()
        {
            Retailer testRetailer = new Retailer();
            testRetailer.retailerName = "testRetailer";
            testRetailer.retailerEmail = "*****@*****.**";
            testRetailer.retailerContactName = "testContact";

            RetailersController controller = new RetailersController();

            var result = (RedirectToRouteResult)controller.Create(testRetailer);

            Assert.AreEqual("Index", result.RouteValues["action"]);
        }
コード例 #3
0
        public ActionResult Create(Retailer retailer)
        {
            if (ModelState.IsValid)
            {
                db.Retailers.Add(retailer);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.employeeID = new SelectList(db.Employees, "employeeID", "employeeFirstName", retailer.employeeID);
            ViewBag.suburbID = new SelectList(db.Suburbs, "suburbID", "suburb1", retailer.suburbID);
            return View(retailer);
        }
コード例 #4
0
 public ActionResult Edit(Retailer retailer)
 {
     if (ModelState.IsValid)
     {
         db.Entry(retailer).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     ViewBag.employeeID = new SelectList(db.Employees, "employeeID", "employeeFirstName", retailer.employeeID);
     ViewBag.suburbID = new SelectList(db.Suburbs, "suburbID", "suburb1", retailer.suburbID);
     return View(retailer);
 }