示例#1
0
        public async Task <SearchResultModel <BranchModel> > GetBranchesByFilter(BranchSearchViewModel filters)
        {
            if (Branches.Count == 0)
            {
                Branches = await Task.Run(() => Builder <BranchModel> .CreateListOfSize(100).Build().ToList());
            }
            SearchResultModel <BranchModel> searchResult = new SearchResultModel <BranchModel>();
            var BranchQueryable           = Branches.Where(x => string.IsNullOrEmpty(filters.Name) || x.Name.Contains(filters.Name)).AsQueryable();
            List <BranchModel> BranchList = await Task.Run(() => BranchQueryable.OrderBy(x => x.Name).Skip((filters.CurrentPage - 1) * filters.RecordsPerPage).Take(filters.RecordsPerPage).ToList());

            searchResult.ResultList = Conventors.ToObservableCollection(BranchList ?? new List <BranchModel>());
            if (filters.CalculateTotal)
            {
                searchResult.TotalCount = BranchQueryable == null ? 0 : BranchQueryable.Count();
            }
            return(searchResult);
        }
示例#2
0
        public JsonResult Search(BranchSearchViewModel model)
        {
            Response response;

            try
            {
                List <Branch> list;
                int           dataCount;
                using (var db = new KiaGalleryContext())
                {
                    var query = db.Branch.Select(x => x);

                    dataCount = query.Count();
                    query     = query.OrderBy(x => x.Order).Skip(model.page * model.count).Take(model.count);

                    list = query.ToList();
                }

                response = new Response()
                {
                    status = 200,

                    data = new
                    {
                        list = list.Select(item => new
                        {
                            id     = item.Id,
                            alias  = item.Alias,
                            name   = item.Name,
                            order  = item.Order,
                            color  = item.Color,
                            active = item.Active
                        }),
                        pageCount = Math.Ceiling((double)dataCount / model.count),
                        count     = dataCount,
                        page      = model.page + 1
                    }
                };
            }
            catch (Exception ex)
            {
                response = Core.GetExceptionResponse(ex);
            }

            return(Json(response, JsonRequestBehavior.AllowGet));
        }