示例#1
0
        private async Task getItems()
        {
            RecommendedListVM vm = getPersistantData <RecommendedListVM>();

            vm.items = await ItemsAPI.getItems();

            setPersistantData(vm);
        }
示例#2
0
        public async Task <IActionResult> openItemList()
        {
            BlockListVM vm = getPersistantData <BlockListVM>();

            vm.items = await ItemsAPI.getItems();

            if (vm.hiddenCategories == null)
            {
                vm = applyDefaultFilters(vm);
            }

            setPersistantData(vm);
            return(RedirectToAction("Index"));
        }
示例#3
0
        public async Task <IActionResult> openItemList(string message)
        {
            ItemInformationList il = getPersistantData <ItemInformationList>();

            il.items = await ItemsAPI.getItems();

            if (il.hiddenCategories == null)
            {
                il = applyDefaultFilters(il);
            }
            setPersistantData(il);
            il.cart_count = await Models.User.getCartCount();

            il.success_message = message;
            return(View("~/Information/Views/ItemInformationList.cshtml", il));
        }
示例#4
0
        public async static Task <RecommendedList> getList(User user)
        {
            return(await DB.doInTrasaction(async cmd =>
            {
                // Initialize list as empty list
                RecommendedList list = new RecommendedList(user)
                {
                    id = -1,
                };

                // Select list
                cmd.CommandText = "SELECT id FROM recommended_lists WHERE user_id = @id;";
                cmd.Parameters.AddWithValue("@id", user.id);

                using (var reader = await cmd.ExecuteReaderAsync())
                {
                    if (reader.Read())
                    {
                        list.id = reader.GetInt32(reader.GetOrdinal("id"));
                    }
                }

                // If a list was found, try to search for it's contents
                if (list.id != -1)
                {
                    cmd.Parameters.Clear();
                    cmd.CommandText = "SELECT item_id FROM recommended_list_items WHERE recommended_list_id = @id;";
                    cmd.Parameters.AddWithValue("@id", list.id);

                    List <int> itemIds = new List <int>();

                    using (var reader = await cmd.ExecuteReaderAsync())
                    {
                        while (reader.Read())
                        {
                            itemIds.Add(reader.GetInt32(reader.GetOrdinal("item_id")));
                        }
                    }

                    list.items = (await ItemsAPI.getItems(itemIds)).ToList();
                }

                return list;
            }));
        }
示例#5
0
        public static async Task <Cart> getCart(int user_id)
        {
            return(await DB.doInTrasaction(async (cmd) =>
            {
                Cart cart = new Cart();
                cmd.CommandText = "SELECT * FROM carts WHERE user_id = @user_id AND ordered = FALSE LIMIT 1;";
                cmd.Parameters.AddWithValue("@user_id", user_id);

                using (var reader = await cmd.ExecuteReaderAsync())
                {
                    if (reader.Read())
                    {
                        cart.id = reader.GetInt32(reader.GetOrdinal("id"));
                        cart.user_id = reader.GetInt32(reader.GetOrdinal("user_id"));
                    }
                }

                //---------------------
                // Fetch cart items

                // Fetch all possible shop items
                IEnumerable <ShopItem> shopItems = (await ItemsAPI.getItems()).SelectMany(i => i.shop_items);

                // Fetch shop item ids in the cart
                List <int> ids = new List <int>();
                cmd.CommandText = "SELECT * FROM cart_items WHERE cart_id = @cart_id;";
                cmd.Parameters.AddWithValue("@cart_id", cart.id);

                using (var reader = await cmd.ExecuteReaderAsync())
                {
                    while (reader.Read())
                    {
                        ids.Add(reader.GetInt32(reader.GetOrdinal("shop_item_id")));
                    }
                }

                // Transform shop item ids to shop items
                cart.items = ids.Select(i => shopItems.First(si => si.id == i)).ToList();

                return cart;
            }));
        }