Ejemplo n.º 1
0
        public ActionResult DeleteUserConfirmed(int id)
        {
            // If selected user is admin or cashier, it will show different msg, you can go to the view and see the if statement
            var checkAdmin = AllUsers.GetUsers().Where(c => c.ID == id && (c.Roles == Roles.Admin || c.Roles == Roles.Cashier)).SingleOrDefault();

            var checkCustomer = AllUsers.GetUsers().Where(c => c.ID == id && c.Roles == Roles.Customer).SingleOrDefault();

            if (checkAdmin != null)
            {
                AllUsers.RemoveUser(checkAdmin);
            }
            else if (checkCustomer != null)
            {
                // Find which table is reserved by this checkCustomer
                var checkTable = Table.GetTables().Where(c => c.ID == checkCustomer.ID).SingleOrDefault();

                if (checkTable != null)
                {
                    // Check which order in this table
                    var checkOrder = OrderCart.GetOrderCarts().Where(c => c.TablesID == checkTable.TablesID).ToList();

                    OrderCart.RemoveRangeOrderCart(checkOrder);
                    checkTable.TotalQuantity = 0;
                    checkTable.TotalAmount   = 0;
                    checkTable.TStatus       = TStatus.Empty;
                    checkTable.ID            = null;
                    Table.UpdateTable(checkTable);
                    AllUsers.RemoveUser(checkCustomer);
                }
                else
                {
                    AllUsers.RemoveUser(checkCustomer);
                }
            }
            return(RedirectToAction("Users"));
        }
 public ActionResult Edit([Bind(Include = "TableId,TableStatus,TableNumber,UserId")] Table table)
 {
     if (ModelState.IsValid)
     {
         //db.Entry(table).State = EntityState.Modified;
         //db.SaveChanges();
         if (table.TableStatus == TableStatus.Empty)
         {
             table.UserId = null;
         }
         cashierRepo.UpdateTable(table);
         return(RedirectToAction("Index"));
     }
     //ViewBag.UserId = new SelectList(db.User, "Id", "Username", table.UserId);
     ViewBag.UserId = new SelectList(adminRepo.GetUsers(), "Id", "Username", table.UserId);
     return(View(table));
 }
Ejemplo n.º 3
0
        public ActionResult EditTable([Bind(Include = "TablesID,TableNo,TStatus,TotalAmount,TotalQuantity,ID")] Tables table)
        {
            // Get the selected table after you click the edit
            var EditTable = Table.GetTables().Where(c => c.TablesID == table.TablesID).SingleOrDefault();

            // Get other table that the Table No is not same as selected Table No from the Tables database
            var FilterTable = Table.GetTables().Where(c => c.TableNo != EditTable.TableNo).ToList();

            // Check the Table No got same as what u typed got duplicate or not
            var CheckDuplicate = FilterTable.Where(c => c.TableNo == table.TableNo).SingleOrDefault();

            if (ModelState.IsValid)
            {
                try
                {
                    if (CheckDuplicate != null)
                    {
                        throw new Exception("Table No Duplicate");
                    }

                    EditTable.TableNo = table.TableNo;
                    EditTable.TStatus = table.TStatus;
                    if (EditTable.TStatus == TStatus.Empty)
                    {
                        EditTable.TotalQuantity = 0;
                        EditTable.TotalAmount   = 0;
                        EditTable.ID            = null;
                    }
                    ViewbagSuccess("Edit Table Successful.");
                    Table.UpdateTable(EditTable);
                    return(View(EditTable));
                }
                catch (Exception lol)
                {
                    ViewbagError(lol.Message);
                }
            }
            return(View(table));
        }
Ejemplo n.º 4
0
        public ActionResult ClickOrder(int?id)
        {
            // Get the login user id
            var GetUser = Convert.ToInt32(Session["CustomerID"]);

            // Find which category u clicked
            Categories category = Category.GetCategory(id);

            if (category == null)
            {
                return(RedirectToAction("Menu"));
            }
            // Grab the ordercart properties
            OrderCart AddOrder = new OrderCart();

            // Find which table foreign key of ID is related to GetUser
            var checkTable = Table.GetTables().Where(c => c.ID == GetUser).SingleOrDefault();

            var    TotalOrder  = 0;
            double TotalAmount = 0;

            if (checkTable != null)
            {
                // Find which orders are related to the category and the table
                OrderCart ordercart = OrderCart.GetOrderCarts().Where(c => c.CategoryID == id && c.TablesID == checkTable.TablesID).SingleOrDefault();

                if (ordercart == null)
                {
                    AddOrder.Quantity     = 1;
                    AddOrder.TotalAmount += category.Price;
                    AddOrder.CategoryID   = category.CategoryID;
                    AddOrder.TablesID     = checkTable.TablesID;
                    OrderCart.AddOrderCart(AddOrder);
                }
                else
                {
                    ordercart.Quantity    += 1;
                    ordercart.TotalAmount += category.Price;
                    OrderCart.UpdateOrderCart(ordercart);
                }
                checkTable.TotalQuantity += 1;
                checkTable.TotalAmount   += category.Price;
                Table.UpdateTable(checkTable);
            }
            else
            {
                // Check the enough table or not
                var checkTables = Table.GetTables().Where(c => c.TStatus == TStatus.Occupied).ToList();

                if (Table.GetTables().Count() == checkTables.Count())
                {
                    Session["NoTable"] = "Sorry, currently is full. Please wait for a few mins.";
                    return(RedirectToAction("Menu"));
                }

                AddOrder.Quantity     = 1;
                AddOrder.TotalAmount += category.Price;
                AddOrder.CategoryID   = category.CategoryID;

                TotalOrder++;
                TotalAmount += category.Price;

                // Loop over the tables and check which table status is empty
                foreach (var item in Table.GetTables())
                {
                    if (item.TStatus == TStatus.Empty)
                    {
                        AddOrder.TablesID  = item.TablesID;
                        item.ID            = GetUser;
                        item.TotalQuantity = 1;
                        item.TotalAmount  += category.Price;
                        item.TStatus       = TStatus.Occupied;
                        Table.UpdateTable(item);
                        break;
                    }
                }
                OrderCart.AddOrderCart(AddOrder);
            }

            var checkTableAfterAdd = Table.GetTables().Where(c => c.ID == GetUser).SingleOrDefault();

            // Find which order is related to the checkTable
            var GetOrderCount = OrderCart.GetOrderCarts().Where(c => c.TablesID == checkTableAfterAdd.TablesID).ToList();

            // Loop over the orders, and get the total of order and amount
            foreach (var item in GetOrderCount)
            {
                TotalOrder += item.Quantity;
            }

            Session["NewOrder"] = category.FoodName + " added into Order";
            ViewBag.MyOrder     = TotalOrder;

            return(RedirectToAction("Menu"));
        }