public ActionResult OpenTable(Order order) { HttpCookie aCookie = Request.Cookies["UserSettings"]; if (aCookie == default(HttpCookie)) { return RedirectToAction("Index"); } else { if (aCookie["Role"] == "Staff" || aCookie["Role"] == "SystemAdmin") { RestaurantDatabaseEntities db = new RestaurantDatabaseEntities(); order.orderStartDate = DateTime.UtcNow; if (ModelState.IsValid) { db.Orders.Add(order); db.SaveChanges(); Order orderID = db.Orders.Where(x => ((x.staffID == order.staffID) && (x.customerID == order.customerID))).OrderByDescending(x => x.orderID).First(); return RedirectToAction("ManageTable/" + orderID.orderID); } return RedirectToAction("Index/2"); } else { return RedirectToAction("Index"); } } }
public ActionResult ChangeStaff(Order order) { RestaurantDatabaseEntities db = new RestaurantDatabaseEntities(); Order originalOrder = db.Orders.FirstOrDefault(x => x.orderID == order.orderID); if (originalOrder == default(Order)) { return RedirectToAction("Index"); } else { if (originalOrder.generatedReceipt == 0) { originalOrder.staffID = order.staffID; db.Entry(originalOrder).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("ManageTable/" + order.orderID); } else { return RedirectToAction("ManageTable/" + order.orderID + "/7"); } } }
public void OpenTableOrder() { MockContext mockContext = new MockContext(); var homeController = new HomeController() { ControllerContext = new ControllerContext() { HttpContext = mockContext.Http.Object } }; Order myOrder = new Order(); myOrder.customerID = "6"; myOrder.generatedReceipt = 0; myOrder.isPaid = 0; myOrder.orderStartDate = DateTime.UtcNow; myOrder.pointsChoice = "Save"; myOrder.staffID = 1; //act var result = homeController.OpenTable(myOrder) as RedirectToRouteResult; Assert.AreEqual("Index", result.RouteValues["Action"]); mockContext.Cookies.Add(new HttpCookie("UserSettings", "Role=Customer")); result = homeController.OpenTable(myOrder) as RedirectToRouteResult; Assert.AreEqual("Index", result.RouteValues["Action"]); mockContext.Cookies.Clear(); HttpCookie myCookie = new HttpCookie("UserSettings"); myCookie.Values["Role"] = "Staff"; myCookie.Values["ID"] = "1"; mockContext.Cookies.Add(myCookie); result = homeController.OpenTable(myOrder) as RedirectToRouteResult; string action = result.RouteValues["Action"].ToString(); bool response = action.Contains("ManageTable"); Assert.AreEqual(response, true); }