public IEnumerable <ImageDetail> GetFullImageList(ImageTableParams param,
                                                          out int totalRecords, out int displayedRecords)
        {
            totalRecords     = 0;
            displayedRecords = 0;

            var imgList = database.ImageFiles.AsQueryable();

            totalRecords = imgList.Count();

            if (!string.IsNullOrEmpty(param.sSearch))
            {
                imgList = imgList.Where(i => i.Keyword.Contains(param.sSearch) ||
                                        i.Name.Contains(param.sSearch) ||
                                        i.Caption.Contains(param.sSearch));
            }
            if (param.imageContent != (int)ImageInformation.ImageContents.All)
            {
                imgList = imgList.Where(i => i.ImageContent == param.imageContent);
            }
            displayedRecords = imgList.Count();

            string sortCol = param.sColumns.Split(',')[param.iSortCol_0];

            IQueryable <ImageFile> filteredAndSorted = null;

            switch (sortCol.ToLower())
            {
            case "name":
            default:
                if (param.sSortDir_0.ToLower() == "asc")
                {
                    filteredAndSorted = imgList.OrderBy(v => v.Name);
                }
                else
                {
                    filteredAndSorted = imgList.OrderByDescending(v => v.Name);
                }
                break;
            }

            if ((displayedRecords > param.iDisplayLength) && (param.iDisplayLength > 0))
            {
                filteredAndSorted = filteredAndSorted.Skip(param.iDisplayStart).Take(param.iDisplayLength);
            }

            return(filteredAndSorted
                   .Include(i => i.SeriesImageFiles)
                   .Include(i => i.TypicalImageFiles)
                   .Include(i => i.Showrooms)
                   .Include(i => i.eCollateralSections)
                   .ToList().Select(v => ToImageDetail(v)));
        }
示例#2
0
        public JsonResult FullImageList(ImageTableParams param)
        {
            int totalCount = 0, filteredCount = 0;

            using (var iRepository = new ImageRepository())
            {
                var results = iRepository.GetFullImageList(
                    param, out totalCount, out filteredCount);

                return(Json(new
                {
                    sEcho = param.sEcho,
                    iTotalRecords = totalCount,
                    iTotalDisplayRecords = filteredCount,
                    aaData = results
                },
                            JsonRequestBehavior.AllowGet));
            }
        }