Inheritance: PetShop.Services.ProductServiceBase
Esempio n. 1
0
        /// <summary>
        /// Rebind control 
        /// </summary>
        protected void PageChanged(object sender, DataGridPageChangedEventArgs e)
        {
            //reset index
            searchList.CurrentPageIndex = e.NewPageIndex;

            //get category id
            string keywordKey = Request.QueryString["keywords"];

            //ProductList list = ProductList.NewList();
            var list = new List<Product>();
            var allProducts = new ProductService().GetAll();
            foreach (Product product in allProducts)
            {
                bool isResult = product.Name.ToLowerInvariant().Contains(keywordKey.ToLowerInvariant()) ||
                                product.Descn.ToLowerInvariant().Contains(keywordKey.ToLowerInvariant());

                if (isResult)
                {
                    list.Add(product);
                }
            }

            //bind data
            searchList.DataSource = list;
            searchList.DataBind();
        }
Esempio n. 2
0
        /// <summary>
        /// Rebind control 
        /// </summary>
        protected void PageChanged(object sender, DataGridPageChangedEventArgs e)
        {
            //reset index
            productsList.CurrentPageIndex = e.NewPageIndex;

            //get category id
            string categoryId = Request.QueryString["categoryId"];

            //bind data
            var productService = new ProductService();
            productsList.DataSource = productService.GetByCategoryId(categoryId);
            productsList.DataBind();
        }
Esempio n. 3
0
        private static void AddCartItem(ref Profile profile, string itemId, int quantity)
        {
            int index = 0;
            bool found = false;

            foreach (Cart cart in profile.WishList)
            {
                if (cart.ItemId == itemId)
                {
                    found = true;
                    break;
                }

                index++;
            }

            if (found)
                profile.WishList[index].Quantity += quantity;
            else
            {
                Item item = new ItemService().GetByItemId(itemId);
                Product product = new ProductService().GetByProductId(item.ProductId);
                Cart cart = new Cart
                                {
                                    UniqueId = profile.UniqueId,
                                    ItemId = itemId,
                                    Name = item.Name,
                                    ProductId = item.ProductId,
                                    IsShoppingCart = false,
                                    Price = item.ListPrice ?? item.UnitCost ?? 0,
                                    Type = product.Name,
                                    CategoryId = product.CategoryId,
                                    Quantity = quantity
                                };

                profile.WishList.Add(cart);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Method to retrieve and cache product name by its ID
        /// </summary>
        /// <param name="productId">Product id</param>
        /// <returns>Product name</returns>
        public static string GetProductName(string productId)
        {
            var productService = new ProductService();
            if (!enableCaching)
                return productService.GetByProductId(productId).Name;

            string cacheKey = string.Format(PRODUCT_NAME_KEY, productId);

            // Check if the data exists in the data cache
            var data = (string) HttpRuntime.Cache[cacheKey];

            if (data == null)
            {
                // Caching duration from Web.config
                int cacheDuration = int.Parse(ConfigurationManager.AppSettings["ProductCacheDuration"]);

                // If the data is not in the cache then fetch the data from the business logic tier
                data = productService.GetByProductId(productId).Name;

                // Store the output in the data cache, and Add the necessary AggregateCacheDependency object
                HttpRuntime.Cache.Add(cacheKey, data, null, DateTime.Now.AddHours(cacheDuration),
                                      Cache.NoSlidingExpiration, CacheItemPriority.High, null);
            }

            return data;
        }