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); }
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"]); }
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); }
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); }