Exemple #1
0
        public List <ProductDTO> GetAllProducts()
        {
            if (HttpContext.Current.Cache[keyAllProduct] != null)
            {
                return((List <ProductDTO>)HttpContext.Current.Cache[keyAllProduct]);
            }
            List <ProductDTO> list =
                ProductManage.GetAllProducts().Select(u => new ProductDTO
            {
                ProductId      = u.ProductId,
                ProductName    = u.ProductName,
                ProductSEOName = u.ProductSEOName,
                Category       = u.Category,
                ProductPrice   = u.ProductPrice,
                ProductCount   = u.ProductCount,
                Discount       = u.Discount,
                Tax            = u.Tax,
                Shipping       = u.Shipping,
                Status         = u.Status,
                ImagePath      = u.ImagePath
            }).ToList();

            HttpContext.Current.Cache.Insert(keyAllProduct, list, null,
                                             DateTime.Now.ToUniversalTime().AddMinutes(10),
                                             Cache.NoSlidingExpiration);
            return(list);
        }
        public ActionResult Index()
        {
            ViewBag.Title = "Welcome to free eshop platform.";

            return(View(ProductManage.GetAllProducts()));
            //return View();
        }
        public JsonResult GetProducts(int?page, int?limit, string sortBy, string direction, string searchString = null)
        {
            int total   = 0;
            var records = new object();

            try
            {
                records = ProductManage.GetAllProducts(page, limit, sortBy, direction, searchString, out total);
            }
            catch (Exception e)
            {
                records = "error:" + e.Message;
            }
            return(Json(new { records, total }, JsonRequestBehavior.AllowGet));
        }