Ejemplo n.º 1
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");
                }
            }
        }
Ejemplo n.º 2
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");
         }
     }
 }