Exemplo n.º 1
0
        public static void UpdateCartDB(string action, string itemName)
        {
            RestaurantAppDBEntities DB = new RestaurantAppDBEntities();

            switch (action)
            {
            case "ADD":
            {
                int menuPK = 0;
                var menu   = from m in DB.Menus
                             where m.ItemName == itemName
                             select m;
                menuPK = menu.ToList()[0].pk;
                RestaurantDB.Cart tmp = new RestaurantDB.Cart();
                tmp.fk_user = theCart.pk;
                tmp.fk_item = menuPK;
                DB.Carts.Add(tmp);
                DB.SaveChanges();
            }
            break;

            case "DEL":
            {
                int menuPK = 0;
                var menu   = from m in DB.Menus
                             where m.ItemName == itemName
                             select m;
                menuPK = menu.ToList()[0].pk;
                int amount = 0;
                var cart   = from c in DB.Carts
                             where c.fk_user == theCart.pk
                             select c;

                RestaurantDB.Cart tmp = new RestaurantDB.Cart();
                foreach (var i in cart)
                {
                    if (i.fk_item == menuPK)
                    {
                        amount++;
                        tmp = i;
                    }
                }
                DB.Carts.Remove(tmp);
                //for (int i = 0; i < amount - 1; i++)
                //{
                //    DB.Carts.Add(tmp);
                //}
                DB.SaveChanges();
            }
            break;

            default:
                break;
            }
        }
Exemplo n.º 2
0
        public static void LoadCart(string userName, string Password)
        {
            RestaurantAppDBEntities DB = new RestaurantAppDBEntities();
            var user = from u in DB.Users
                       where u.UserName == userName && u.UserPassword == Password
                       select u;

            if (user.ToList().Count == 0)
            {
                User userTmp = new User();
                userTmp.UserName     = userName;
                userTmp.UserPassword = Password;
                userTmp.UserAddress  = "Unknown";
                DB.Users.Add(userTmp);
                DB.SaveChanges();

                user = from u in DB.Users
                       where u.UserName == userName && u.UserPassword == Password
                       select u;
            }

            theCart.name     = user.ToList()[0].UserName;
            theCart.address  = user.ToList()[0].UserAddress;
            theCart.password = user.ToList()[0].UserPassword;
            theCart.pk       = user.ToList()[0].pk;
            theCart.items.Clear();

            var cart = from c in DB.Carts
                       where c.fk_user == theCart.pk
                       select c;

            foreach (var i in cart)
            {
                var menu = from m in DB.Menus
                           where m.pk == i.fk_item
                           select m;

                if (menu.ToList()[0].ItemName != null)
                {
                    AddToCart(menu.ToList()[0].ItemName, 1, menu.ToList()[0].Price);
                }
            }
        }
Exemplo n.º 3
0
        public static void FillDefaultMenu()
        {
            theMenu = new List <MenuCategory>();
            RestaurantAppDBEntities database = new RestaurantAppDBEntities();

            foreach (var c in database.Categories)
            {
                MenuCategory tmp = new MenuCategory();
                tmp.name = c.category1;
                var list = from m in database.Menus where m.fk_Category == c.pk select m;
                foreach (var i in list)
                {
                    MenuItem tmp2 = new MenuItem();
                    tmp2.name  = i.ItemName;
                    tmp2.price = i.Price;
                    tmp.list.Add(tmp2);
                }
                theMenu.Add(tmp);
            }
        }