Пример #1
0
        public CommodityDatatables GetCommodityForTable(int page, int itemsPerPage, string sortBy, bool reverse, string commoditySearchValue)
        {
            var commodity = _commodityRepository.GetAllQueryable();

            // searching
            if (!string.IsNullOrWhiteSpace(commoditySearchValue))
            {
                commoditySearchValue = commoditySearchValue.ToLower();
                commodity            = commodity.Where(com => com.CommodityC.ToLower().Contains(commoditySearchValue) ||
                                                       com.CommodityN.ToLower().Contains(commoditySearchValue)
                                                       );
            }

            var commodityOrdered = commodity.OrderBy(sortBy + (reverse ? " descending" : ""));

            // paging
            var commodityPaged = commodityOrdered.Skip((page - 1) * itemsPerPage).Take(itemsPerPage).ToList();

            var destination  = Mapper.Map <List <Commodity_M>, List <CommodityViewModel> >(commodityPaged);
            var comDatatable = new CommodityDatatables()
            {
                Data  = destination,
                Total = commodity.Count()
            };

            return(comDatatable);
        }