public ActionResult AddItem(Item item)
 {
     HttpCookie myCookie = Request.Cookies["UserSettings"];
     if (myCookie == default(HttpCookie))
     {
         return RedirectToAction("Index");
     }
     else
     {
         if (myCookie["Role"] != "Staff")
         {
             return RedirectToAction("Index");
         }
         else
         {
             RestaurantDatabaseEntities db = new RestaurantDatabaseEntities();
             if (ModelState.IsValid)
             {
                 db.Items.Add(item);
                 db.SaveChanges();
             }
             return RedirectToAction("ViewMenu");
         }
     }
 }
 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)
 //{
 //    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 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 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 CreateStaffAccount(Staff staff)
 {
     HttpCookie aCookie = Request.Cookies["UserSettings"];
     if (aCookie == default(HttpCookie))
     {
         return RedirectToAction("Index");
     }
     else
     {
         if (aCookie["Role"] == "Staff")
         {
             RestaurantDatabaseEntities db = new RestaurantDatabaseEntities();
             if (staff.staffName == null)
             {
                 return RedirectToAction("CreateStaffAccount/1");
             }
             else
             {
                 if (ModelState.IsValid)
                 {
                     db.Staffs.Add(staff);
                     db.SaveChanges();
                     return RedirectToAction("Index");
                 }
                 else
                 {
                     return RedirectToAction("CreateStaffAccount/1");
                 }
             }
         }
         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 CreateCustomerAccount(Customer customer)
 {
     HttpCookie aCookie = Request.Cookies["UserSettings"];
     if (aCookie == default(HttpCookie))
     {
         RestaurantDatabaseEntities db = new RestaurantDatabaseEntities();
         if (customer.customerEmail == null || customer.customerAddress == null || customer.customerPass == null || customer.customerPhone == null)
         {
             return RedirectToAction("CreateCustomerAccount/2");
         }
         else
         {
             if (ModelState.IsValid)
             {
                 Customer prevCustomer = db.Customers.FirstOrDefault(x => x.customerEmail == customer.customerEmail);
                 if (prevCustomer == default(Customer))
                 {
                     using (MD5 hash = MD5.Create())
                     {
                         customer.customerPass = GetMd5Hash(hash, customer.customerPass);
                     }
                     db.Customers.Add(customer);
                     db.SaveChanges();
                     customer.customerID = db.Customers.First(x => x.customerEmail == customer.customerEmail).customerID;
                     HttpCookie myCookie = new HttpCookie("UserSettings");
                     myCookie.Values["Email"] = customer.customerEmail;
                     myCookie.Values["Role"] = "Customer";
                     myCookie.Values["ID"] = customer.customerID.ToString();
                     Response.SetCookie(myCookie);
                     return RedirectToAction("CustomerAccount");
                 }
                 else
                 {
                     return RedirectToAction("CreateCustomerAccount/1");
                 }
             }
             else
             {
                 return RedirectToAction("CreateCustomerAccount/2");
             }
         }
     }
     else
     {
         return RedirectToAction("Index");
     }
 }
 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");
         }
     }
 }
Esempio n. 10
0
 public ActionResult News(News news)
 {
     HttpCookie aCookie = Request.Cookies["UserSettings"];
     if (aCookie == default(HttpCookie))
     {
         return RedirectToAction("Index");
     }
     else
     {
         if (aCookie["Role"] == "SystemAdmin")
         {
             RestaurantDatabaseEntities db = new RestaurantDatabaseEntities();
             news.date = DateTime.Now;
             if (ModelState.IsValid)
             {
                 db.News.Add(news);
                 db.SaveChanges();
             }
             return RedirectToAction("Index");
         }
         else
         {
             return RedirectToAction("Index");
         }
     }
 }
Esempio n. 11
0
 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");
         }
     }
 }
Esempio n. 12
0
 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");
             }
         }
     }
 }
Esempio n. 13
0
 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");
         }
     }
 }
Esempio n. 14
0
 // 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");
         }
     }
 }
Esempio n. 15
0
        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");
                }
            }
        }
Esempio n. 16
0
 public ActionResult AddItem(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();
             List<Item> allItems = db.Items.ToList();
             foreach (Item existingItem in allItems)
             {
                 if (existingItem.itemName.ToUpper() == item.itemName.ToUpper())
                 {
                     return RedirectToAction("AddItem/1");
                 }
             }
             if (ModelState.IsValid)
             {
                 db.Items.Add(item);
                 db.SaveChanges();
             }
             return RedirectToAction("ViewMenu");
         }
     }
 }
Esempio n. 17
0
 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");
         }
     }
 }
Esempio n. 18
0
 public ActionResult CreateStaffAccount(Staff staff)
 {
     HttpCookie aCookie = Request.Cookies["UserSettings"];
     if (aCookie == default(HttpCookie))
     {
         return RedirectToAction("Index");
     }
     else
     {
         if (aCookie["Role"] == "SystemAdmin")
         {
             RestaurantDatabaseEntities db = new RestaurantDatabaseEntities();
             if (staff.staffName == null)
             {
                 return RedirectToAction("CreateStaffAccount/1");
             }
             else
             {
                 if (ModelState.IsValid)
                 {
                     Staff existingStaff = db.Staffs.FirstOrDefault(x => x.staffName == staff.staffName);
                     if (existingStaff == default(Staff))
                     {
                         if (staff.password == null || staff.password.Length < 6)
                         {
                             return RedirectToAction("CreateStaffAccount/2");
                         }
                         else
                         {
                             using (MD5 hash = MD5.Create())
                             {
                                 staff.password = GetMd5Hash(hash, staff.password);
                             }
                             db.Staffs.Add(staff);
                             db.SaveChanges();
                             return RedirectToAction("Index");
                         }
                     }
                     else
                     {
                         return RedirectToAction("CreateStaffAccount/1");
                     }
                 }
                 else
                 {
                     return RedirectToAction("CreateStaffAccount/1");
                 }
             }
         }
         return RedirectToAction("Index");
     }
 }
Esempio n. 19
0
 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");
         }
     }
 }
Esempio n. 20
0
        // Tested
        public ActionResult DeleteOrderLine(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.FirstOrDefault(x => x.id == id);
                    if (orderLine == default(OrderLine))
                    {
                        return RedirectToAction("Index");
                    }
                    Order order = db.Orders.Find(orderLine.orderID);
                    if (order == default(Order))
                    {
                        return RedirectToAction("Index");
                    }
                    if (order.staffID == Int32.Parse(aCookie["ID"]) || aCookie["Role"] == "SystemAdmin")
                    {
                        if (order.generatedReceipt == 1)
                        {
                            return RedirectToAction("ManageTable/" + order.orderID + "/4");
                        }
                        else
                        {
                            if (orderLine != default(OrderLine))
                            {

                                db.OrderLines.Remove(orderLine);
                                db.SaveChanges();
                                return RedirectToAction("ManageTable/" + orderLine.orderID);
                            }
                            else
                            {
                                return RedirectToAction("Index");
                            }
                        }
                    }
                    else
                    {
                        return RedirectToAction("Index");
                    }
                }
                else
                {
                    return RedirectToAction("Index");
                }
            }
        }
Esempio n. 21
0
 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");
         }
     }
 }