示例#1
0
        private IEnumerable <UserSelectViewModel> IEnumUserSelectViewModelFactory(UserSelectQuery queryModel)
        {
            int StaffNoUpperBound; //查询值上界
            int StaffNoLowerBound; //查询值下界

            string nameQuery;      //按姓名查询

            nameQuery = queryModel.Name ?? "";

            StaffNoUpperBound = queryModel.No ?? int.MaxValue;
            StaffNoLowerBound = queryModel.No ?? 1;

            Expression <Func <ApplicationUser, bool> > queryExpression =
                p => p.StaffName.Contains(nameQuery) &&
                (p.StaffNo >= StaffNoLowerBound && p.StaffNo <= StaffNoUpperBound);
            //var lq = _mainRepository.EntityItems.Where(p => p.Name.Contains(nameQuery) && (p.No >= StaffNoLowerBound && p.No <= StaffNoUpperBound));

            //var linqVar =  _mainRepository.QueryEntity<Staff>(queryExpression);

            var linqVar = _userRepository.QueryEntity <ApplicationUser>(queryExpression)
                          .Select(p => new UserSelectViewModel
            {
                Id   = p.Id,
                No   = p.StaffNo,
                Name = p.StaffName,
            });

            return(linqVar);
        }
示例#2
0
        //[PagingAction]
        public async Task <PartialViewResult> SelectList([Bind(Prefix = "QueryItems")] UserSelectQuery queryModel, [Bind(Prefix = "PagingInfo")] PagingInfo pagingInfo)
        {
            int pageIndex = pagingInfo?.CurrentPage ?? 1;
            int pageSize  = pagingInfo?.ItemsPerPage ?? 10;
            IEnumerable <UserSelectViewModel> linqVar = IEnumUserSelectViewModelFactory(queryModel);

            var newModel = new ItemListViewModel <UserSelectViewModel>
            {
                ItemViewModels = await Task.FromResult(linqVar.OrderBy(x => x.No).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList()).ConfigureAwait(false),

                PagingInfo = new PagingInfo
                {
                    CurrentPage  = pageIndex,
                    ItemsPerPage = pageSize,
                    TotalItems   = linqVar.Count()
                }
            };

            return(PartialView("_UserSelectListPartial", newModel));
        }