public void SalesOrdersController_Create_isValid()
        {
            SalesOrder testSalesOrder = new SalesOrder();
            testSalesOrder.salesOrderNo = "9999999";
            testSalesOrder.salesOrderDate = DateTime.Now;

            SalesOrdersController controller = new SalesOrdersController();

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

            Assert.AreEqual("Index", result.RouteValues["action"]);
        }
        public ActionResult Create(SalesOrder salesorder)
        {
            if (ModelState.IsValid)
            {
                db.SalesOrders.Add(salesorder);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.retailerID = new SelectList(db.Retailers, "retailerID", "retailerName", salesorder.retailerID);
            return View(salesorder);
        }
        public void SalesOrdersController_Create_isNotValid()
        {
            SalesOrder testSalesOrder = new SalesOrder();
            testSalesOrder.salesOrderNo = "invalid";
            SalesOrdersController controller = new SalesOrdersController();
            controller.ModelState.AddModelError("", "error message");

            var result = controller.Create(testSalesOrder) as ViewResult;
            SalesOrder resultSalesOrders = (SalesOrder)result.Model;

            Assert.AreEqual("invalid", resultSalesOrders.salesOrderNo);
        }
 public ActionResult Edit(SalesOrder salesorder)
 {
     if (ModelState.IsValid)
     {
         db.Entry(salesorder).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     ViewBag.retailerID = new SelectList(db.Retailers, "retailerID", "retailerName", salesorder.retailerID);
     return View(salesorder);
 }