Exemplo n.º 1
0
        public static IEnumerable <CodeDisplayMode> SearchResult(CodeSearchModel searchModel, out int totalCount)
        {
            List <CodeDisplayMode> models = new List <CodeDisplayMode>();
            List <string>          fields = GetCategoryList();

            var date = _codeDAL.SearchModelById().GroupBy(i => i.BCCategory);

            foreach (var item in date)
            {
                CodeDisplayMode model = new CodeDisplayMode
                {
                    Key   = item.Key,
                    Value = string.Join(",", item.ToList().Select(i => i.BCCode).ToArray())
                };
                models.Add(model);
            }

            var result = (from field in fields
                          join model in models on field equals model.Key into temp
                          from tt in temp.DefaultIfEmpty()
                          select new CodeDisplayMode {
                Key = field.ToString(), Value = tt == null ? "" : tt.Value
            }).ToList();

            if (!string.IsNullOrWhiteSpace(searchModel.Key))
            {
                result = result.Where(i => i.Key == searchModel.Key).ToList();
            }
            totalCount = result.Count;
            return(result.AsEnumerable <CodeDisplayMode>());
        }
Exemplo n.º 2
0
        public ActionResult CodeSearchResult(CodeSearchModel searchModel)
        {
            var totalCount = 0;
            var result     = CodeBusiness.SearchResult(searchModel, out totalCount);
            var page       = new Page(totalCount, searchModel.CurrentPage);

            var model = new CodeSearchResultModel
            {
                Models = result.Skip((page.CurrentPage - 1) * page.PageSize).Take(page.PageSize),
                Page   = page
            };

            return(View(model));
        }