// Tested public ActionResult CloseTable(int id) { 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 order = db.Orders.FirstOrDefault(x => x.orderID == id); if (order == default(Order)) { return RedirectToAction("Index"); } else { if (Int32.Parse(aCookie["ID"]) == order.staffID || aCookie["Role"] == "SystemAdmin") { List<OrderLine> orderItems = db.OrderLines.Where(x => x.orderID == id).ToList(); if (order.isPaid == 0 && orderItems.Count > 0) { return RedirectToAction("ManageTable/" + id + "/1"); } else { order.orderEndDate = DateTime.Now; decimal price = 0; foreach (OrderLine orderItem in orderItems) { decimal itemPrice = db.Items.Find(orderItem.itemID).itemPrice; orderItem.price = itemPrice; db.Entry(orderItem).State = EntityState.Modified; price = price + (itemPrice * orderItem.quantity); } order.Price = price; db.Entry(order).State = EntityState.Modified; db.SaveChanges(); } } } return RedirectToAction("Index"); } else { return RedirectToAction("Index"); } } }
public ActionResult CustomerAccount(Customer customer) { HttpCookie aCookie = Request.Cookies["UserSettings"]; if (aCookie == default(HttpCookie)) { return RedirectToAction("Index"); } else { if (aCookie["Role"] == "Customer") { RestaurantDatabaseEntities db = new RestaurantDatabaseEntities(); string currentEmail = aCookie["Email"]; Customer myCustomer = db.Customers.FirstOrDefault(x => x.customerEmail == currentEmail); if (myCustomer == default(Customer)) { return RedirectToAction("CustomerAccount"); } else { Customer checkEmail = db.Customers.FirstOrDefault(x => x.customerEmail == customer.customerEmail); if (checkEmail == default(Customer) || checkEmail.customerID == myCustomer.customerID) { myCustomer.customerEmail = customer.customerEmail; myCustomer.customerAddress = customer.customerAddress; myCustomer.customerPhone = customer.customerPhone; aCookie["Email"] = myCustomer.customerEmail; Response.SetCookie(aCookie); db.Entry(myCustomer).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("CustomerAccount/4"); } else { return RedirectToAction("CustomerAccount/1"); } } } else { return RedirectToAction("Index"); } } }
//public ActionResult ChangeOrderLineQuantity(int id) //{ // HttpCookie aCookie = Request.Cookies["UserSettings"]; // if (aCookie == default(HttpCookie)) // { // return RedirectToAction("Index"); // } // else // { // if (aCookie["Role"] == "Staff" || aCookie["Role"] == "SystemAdmin") // { // RestaurantDatabaseEntities db = new RestaurantDatabaseEntities(); // OrderLine orderLine = db.OrderLines.Find(id); // Order order = db.Orders.Find(orderLine.orderID); // if (order.staffID == Int32.Parse(aCookie["ID"]) || aCookie["Role"] == "SystemAdmin") // { // if (order.generatedReceipt == 1) // { // return RedirectToAction("ManageTable/" + order.orderID + "/5"); // } // else // { // ViewBag.itemName = db.Items.Find(orderLine.itemID).itemName; // if (orderLine == null) // { // return RedirectToAction("Index"); // } // return View("ChangeOrderLineQuantity", orderLine); // } // } // else // { // return RedirectToAction("Index"); // } // } // else // { // return RedirectToAction("Index"); // } // } //} //[HttpPost] //public ActionResult ChangeOrderLineQuantity(OrderLine orderLine) //{ // 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 order = db.Orders.Find(orderLine.orderID); // if (order.staffID == Int32.Parse(aCookie["ID"]) || aCookie["Role"] == "SystemAdmin") // { // if (order.generatedReceipt == 1) // { // return RedirectToAction("ManageTable/" + order.orderID + "/5"); // } // else // { // if (ModelState.IsValid) // { // if (orderLine.quantity <= 0) // { // OrderLine sample = db.OrderLines.Find(orderLine.id); // db.OrderLines.Remove(sample); // db.SaveChanges(); // return RedirectToAction("ManageTable/" + orderLine.orderID); // } // else if (orderLine.quantity > 0) // { // db.Entry(orderLine).State = EntityState.Modified; // db.SaveChanges(); // return RedirectToAction("ManageTable/" + orderLine.orderID); // } // } // return RedirectToAction("ManageTable/" + orderLine.orderID); // } // } // else // { // return RedirectToAction("Index"); // } // } // else // { // return RedirectToAction("Index"); // } // } //} public ActionResult ChangePointsSetting(int id) { 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 myOrder = db.Orders.Find(id); if (myOrder.staffID == Int32.Parse(aCookie["ID"]) || aCookie["Role"] == "SystemAdmin") { if (myOrder.isPaid == 1 || myOrder.generatedReceipt == 1) { return RedirectToAction("ManageTable/" + myOrder.orderID + "/6"); } else { if (myOrder.pointsChoice == "Save") { myOrder.pointsChoice = "Spend"; } else { myOrder.pointsChoice = "Save"; } db.Entry(myOrder).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("ManageTable/" + id); } } else { return RedirectToAction("Index"); } } 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 ActionResult ChangeOrderLineQuantity(int id, int quantity) { HttpCookie aCookie = Request.Cookies["UserSettings"]; if (aCookie == default(HttpCookie)) { return RedirectToAction("Index"); } else { if (aCookie["Role"] == "Staff" || aCookie["Role"] == "SystemAdmin") { RestaurantDatabaseEntities db = new RestaurantDatabaseEntities(); OrderLine orderLine = db.OrderLines.FirstOrDefault(x => x.id == id); if (orderLine == default(OrderLine)) { return RedirectToAction("Index"); } else { Order order = db.Orders.Find(orderLine.orderID); if (order == default(Order)) { return RedirectToAction("Index"); } else { if (order.staffID == Int32.Parse(aCookie["ID"]) || aCookie["Role"] == "SystemAdmin") { if (order.generatedReceipt == 1) { return RedirectToAction("ManageTable/" + order.orderID + "/5"); } else { if (quantity <= 0) { return RedirectToAction("ManageTable/" + order.orderID + "/5"); } else { orderLine.quantity = quantity; db.Entry(orderLine).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("ManageTable/" + orderLine.orderID); } } } } } } } return RedirectToAction("Index"); }
public ActionResult ChangePassword(string currentPassword, string newPass1, string newPass2) { HttpCookie aCookie = Request.Cookies["UserSettings"]; if (aCookie == default(HttpCookie)) { return RedirectToAction("Index"); } else { if (aCookie["Role"] != "Customer") { return RedirectToAction("Index"); } else { RestaurantDatabaseEntities db = new RestaurantDatabaseEntities(); using (MD5 hash = MD5.Create()) { currentPassword = GetMd5Hash(hash, currentPassword); } string customerEmail = aCookie["Email"]; Customer myCustomer = db.Customers.FirstOrDefault(x=>((x.customerEmail == customerEmail) &&(x.customerPass == currentPassword))); if (myCustomer == default(Customer)) { return RedirectToAction("CustomerAccount/2"); } else { using (MD5 hash = MD5.Create()) { newPass1 = GetMd5Hash(hash, newPass1); } myCustomer.customerPass = newPass1; db.Entry(myCustomer).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("CustomerAccount/3"); } } } }
public ActionResult PayOrder(int id) { 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 order = db.Orders.Find(id); if (order.staffID == Int32.Parse(aCookie["ID"]) || aCookie["Role"] == "SystemAdmin") { int errorMessage = 0; if (order.generatedReceipt == 1) { order.isPaid = 1; db.Entry(order).State = EntityState.Modified; db.SaveChanges(); List<OrderLine> allOrderLines = db.OrderLines.Where(x => x.orderID == order.orderID).ToList(); List<Item> allItems = db.Items.ToList(); double totalPrice = 0; foreach (OrderLine orderLine in allOrderLines) { foreach (Item item in allItems) { if (orderLine.itemID == item.itemID) { totalPrice += Convert.ToDouble(item.itemPrice * orderLine.quantity); } } } int pointsEarned = (int)Math.Floor(totalPrice * 10); int customerID = 0; if (order.customerID != null) { customerID = Int32.Parse(order.customerID); } Customer customer = db.Customers.FirstOrDefault(x => x.customerID == customerID); if (customer != default(Customer)) { int customerCurrentPoints = customer.customerLoyaltyPoints; if (order.pointsChoice == "Save") { customer.customerLoyaltyPoints = customerCurrentPoints + pointsEarned; } else if (order.pointsChoice == "Spend") { customer.customerLoyaltyPoints = customerCurrentPoints + pointsEarned; if (totalPrice * 100 >= customer.customerLoyaltyPoints) { customer.customerLoyaltyPoints = 0; } else { customer.customerLoyaltyPoints = customer.customerLoyaltyPoints - (int)(totalPrice * 100); } } db.Entry(customer).State = EntityState.Modified; db.SaveChanges(); } return RedirectToAction("CloseTable/" + order.orderID); } else { errorMessage = 2; } return RedirectToAction("ManageTable/" + id + "/" + errorMessage); } else { return RedirectToAction("Index"); } } else { return RedirectToAction("Index"); } } }
public ActionResult ChangeCustomerID(string customerID, int orderID) { HttpCookie aCookie = Request.Cookies["UserSettings"]; if (aCookie == default(HttpCookie)) { return RedirectToAction("Index"); } else { if (aCookie["Role"] == "Staff" || aCookie["Role"] == "SystemAdmin") { RestaurantDatabaseEntities db = new RestaurantDatabaseEntities(); int custID = 0; if (customerID == "") { } else { custID = Int32.Parse(customerID); } Customer customer = db.Customers.FirstOrDefault(x => x.customerID == custID); Order order = db.Orders.Find(orderID); if (order.staffID == Int32.Parse(aCookie["ID"]) || aCookie["Role"] == "SystemAdmin") { if (customerID == "" || customerID == "0") { order.customerID = null; db.Entry(order).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("ManageTable/" + orderID); } else { if (customer == default(Customer)) { ViewBag.ErrorMessage = "The customer ID was not found."; return View("ChangeCustomerID", order); } else { order.customerID = customer.customerID.ToString(); db.Entry(order).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("ManageTable/" + orderID); } } } else { return RedirectToAction("Index"); } } else { return RedirectToAction("Index"); } } }
public ActionResult AddItemToOrderJS(int orderID, int itemID, int quantity) { 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 order = db.Orders.Find(orderID); if (order.staffID == Int32.Parse(aCookie["ID"]) || aCookie["Role"] == "SystemAdmin") { if (order.generatedReceipt == 1) { return RedirectToAction("ManageTable/" + order.orderID + "/3"); } else { if (quantity <= 0) { } else { OrderLine check = db.OrderLines.FirstOrDefault(x => (x.itemID == itemID && x.orderID == orderID)); if (check != default(OrderLine)) { check.quantity += quantity; db.Entry(check).State = EntityState.Modified; db.SaveChanges(); } else if (check == default(OrderLine)) { OrderLine orderLine = new OrderLine(); orderLine.itemID = itemID; orderLine.orderID = orderID; orderLine.quantity = quantity; db.OrderLines.Add(orderLine); db.SaveChanges(); } } order.generatedReceipt = 0; db.Entry(order).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("ManageTable/" + orderID); } } else { return RedirectToAction("Index"); } } else { return RedirectToAction("Index"); } } }
public ActionResult GenerateHTMLReceipt(int id) { 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 order = db.Orders.Find(id); if (order.staffID == Int32.Parse(aCookie["ID"]) || aCookie["Role"] == "SystemAdmin") { ViewBag.staffName = db.Staffs.FirstOrDefault(x => x.staffID == order.staffID).staffName; ViewBag.allItems = db.Items.ToList(); ViewBag.allOrderLines = db.OrderLines.Where(x => x.orderID == id); int customerID = 0; if (order.customerID != null) { customerID = Int32.Parse(order.customerID); } Customer customer = db.Customers.FirstOrDefault(x => x.customerID == customerID); ViewBag.CustomerEmail = ""; ViewBag.CustomerID = null; ViewBag.CustomerCurrentPoints = 0; if (customer != default(Customer)) { ViewBag.CustomerEmail = customer.customerEmail; ViewBag.CustomerID = customer.customerID; ViewBag.CustomerCurrentPoints = customer.customerLoyaltyPoints; } order.generatedReceipt = 1; db.Entry(order).State = EntityState.Modified; db.SaveChanges(); return View("GenerateHTMLReceipt", order); } else { return RedirectToAction("Index"); } } else { return RedirectToAction("Index"); } } }
public ActionResult EditItem(Item item) { HttpCookie myCookie = Request.Cookies["UserSettings"]; if (myCookie == default(HttpCookie)) { return RedirectToAction("Index"); } else { if (myCookie["Role"] != "SystemAdmin") { return RedirectToAction("Index"); } else { RestaurantDatabaseEntities db = new RestaurantDatabaseEntities(); if (ModelState.IsValid) { db.Entry(item).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("ViewMenu"); } else { return View("Index"); } } } }
public ActionResult DiscardReceipt(int id) { 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 order = db.Orders.Find(id); if (order.staffID == Int32.Parse(aCookie["ID"]) || aCookie["Role"] == "SystemAdmin") { if (order.isPaid == 1) { return RedirectToAction("ManageTable/" + id + "/7"); } else { order.generatedReceipt = 0; db.Entry(order).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("ManageTable/" + id); } } else { return RedirectToAction("Index"); } } else { return RedirectToAction("Index"); } } }
public ActionResult ChangeOrderLineQuantity(OrderLine orderLine) { HttpCookie aCookie = Request.Cookies["UserSettings"]; if (aCookie == default(HttpCookie)) { return RedirectToAction("Index"); } else { if (aCookie["Role"] == "Staff") { RestaurantDatabaseEntities db = new RestaurantDatabaseEntities(); Order order = db.Orders.Find(orderLine.orderID); if (order.generatedReceipt == 1) { return RedirectToAction("ManageTable/" + order.orderID + "/5"); } else { if (ModelState.IsValid) { if (orderLine.quantity <= 0) { OrderLine sample = db.OrderLines.Find(orderLine.id); db.OrderLines.Remove(sample); db.SaveChanges(); return RedirectToAction("ManageTable/" + orderLine.orderID); } else if (orderLine.quantity > 0) { db.Entry(orderLine).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("ManageTable/" + orderLine.orderID); } } return RedirectToAction("ManageTable/" + orderLine.orderID); } } else { return RedirectToAction("Index"); } } }