public ActionResult Index()
 {
     baioEntities db = new baioEntities();
     ViewData["Categories"] = db.sp_ProductGetAllbyPaging(1,50,0,false,FirmID);
     return View();
 }
        public JsonResult GetProducts(DataTableParameters param)
        {
            baioEntities db = new baioEntities();
            //string CategoryType = param.pageType;
            //IEnumerable<sp_ProductGetAllbyPaging_Result> data = db.sp_ProductGetAllbyPaging(1, param.iDisplayLength, 0,false).ToList();

            IEnumerable<sp_ProductGetAllbyPaging_Result> data = db.sp_ProductGetAllbyPaging((param.iDisplayStart / param.iDisplayLength) + 1, param.iDisplayLength, 0, false,1).ToList();

            string sKey;

            if (!string.IsNullOrEmpty(param.sSearch))
            {

                sKey = param.sSearch.ToLower();
                data = data.Where(x => !string.IsNullOrEmpty(x.Name) ? x.Name.ToLower().Contains(sKey) : true);
            }
            var sortColumnIndex = Convert.ToInt32(Request["iSortCol_0"]);
            Func<sp_ProductGetAllbyPaging_Result, string> orderingFunction = (p => sortColumnIndex == 1 ? p.Name :
               sortColumnIndex == 2 ? p.Stock.ToString() :
               p.Price.ToString());

            var pagedData = data.OrderBy(x => x.Rank);
            var sortDirection = Request["sSortDir_0"];
            if (sortDirection == "asc")
                pagedData = pagedData.OrderBy(orderingFunction);
            else
                pagedData = pagedData.OrderByDescending(orderingFunction);

            //string CacheKey = CategoryType + param.iDisplayLength + param.iDisplayStart + param.sSearch + param.iDisplayLength + sortColumnIndex + sortDirection;
            //var _Context = System.Web.HttpContext.Current;
            //var PageCache = _Context.Cache.Get(CacheKey) as List<sp_GetPagesLite_Result>;
            var lastData = new List<sp_ProductGetAllbyPaging_Result>();
            //if (PageCache == null)
            //if (true)
            //{
                lastData = pagedData
                  //  .Skip(param.iDisplayStart / param.iDisplayLength * param.iDisplayLength)
                  //.Take(param.iDisplayLength)
                  .Select(x => new sp_ProductGetAllbyPaging_Result
                  {
                     ImageSrc = x.ImageSrc,
                     Total = x.Total,
                     ID = x.ID,
                     Name = x.Name,
                     IsActive = x.IsActive,
                     Stock = x.Stock,
                     OrderCount = x.OrderCount,
                     Variant = x.Variant,
                      Price = x.Price
                  }).ToList();
                //_Context.Cache.Add(CacheKey, lastData, null, System.Web.Caching.Cache.NoAbsoluteExpiration, new TimeSpan(6, 0, 0), System.Web.Caching.CacheItemPriority.Default, null);
            //}
            //else
            //{
            //    lastData = PageCache;
            //}

            return Json(new
            {
                sEcho = param.sEcho,
                iTotalRecords = data.Count(),
                iTotalDisplayRecords = data.FirstOrDefault() != null ? data.FirstOrDefault().Total : 0,
                aaData = lastData
            },
            JsonRequestBehavior.AllowGet);
        }