コード例 #1
0
        /// <summary>
        ///     The get cart.
        /// </summary>
        /// <returns>
        ///     The <see cref="List" />.
        /// </returns>
        public List<CartProduct> GetCart()
        {
            var products = new List<CartProduct>();
            var dalProduct = new DataAccessLayer.Product();

            HttpCookie cookie = this.HttpContext.Request.Cookies["cart"];
            if (cookie != null)
            {
                var items = cookie.Values.AllKeys.SelectMany(
                    cookie.Values.GetValues,
                    (key, value) => new { id = key, amount = value });

                foreach (var item in items)
                {
                    BusinessObjectLayer.Product product = dalProduct.GetBy("Id", item.id);

                    if (product != null)
                    {
                        products.Add(new CartProduct(int.Parse(item.amount), product));
                    }
                }
            }

            return products;
        }