예제 #1
0
        public JsonResult OnGetListAsync(string q, int?page)
        {
            var query = (from a in _context.Country
                         select a
                         );

            if (!string.IsNullOrWhiteSpace(q))
            {
                query = query.Where(u => u.Name.Contains(q));
            }

            X.PagedList.IPagedList <Country> pagedCountries = query.ToPagedList(page ?? 1, 30);
            List <Select2ResultDTO>          result         = new List <Select2ResultDTO>();

            foreach (var item in pagedCountries)
            {
                Select2ResultDTO temp = new Select2ResultDTO();
                temp.id   = item.Id.ToString();
                temp.text = item.Name;
                result.Add(temp);
            }
            Select2PaginateDTO select2PaginateDTO = new Select2PaginateDTO();

            select2PaginateDTO.more = pagedCountries.HasNextPage;
            Select2DTO select2DTO = new Select2DTO();

            select2DTO.results  = result;
            select2DTO.paginate = select2PaginateDTO;
            return(new JsonResult(select2DTO));
        }
예제 #2
0
        public X.PagedList.IPagedList <MembershipUser> GetUsers(int pageIndex, int pageSize, string search, string orderByField)
        {
            var membershipUsers = _membershipUserRepository.Where(x => x.IsDeleted == false);

            if (!string.IsNullOrEmpty(search))
            {
                membershipUsers = membershipUsers.Where(x => x.UserName.Contains(search) || x.Email.Contains(search));
            }

            X.PagedList.IPagedList <MembershipUser> membershipUserResult = null;
            if (!string.IsNullOrEmpty(orderByField))
            {
                if (orderByField == "Email")
                {
                    membershipUserResult = membershipUsers.OrderBy(x => x.Email).ToPagedList(pageIndex, pageSize);
                }
                else if (orderByField == "UserName")
                {
                    membershipUserResult = membershipUsers.OrderBy(x => x.UserName).ToPagedList(pageIndex, pageSize);
                }
            }
            else
            {
                membershipUserResult = membershipUsers.OrderBy(x => x.Id).ToPagedList(pageIndex, pageSize);
            }
            return(membershipUserResult);
        }
예제 #3
0
        public ActionResult Index(int?pageIndex, int?pageSize, string search, string orderby)
        {
            if (pageIndex == null)
            {
                pageIndex = 1;
            }
            if (pageSize == null)
            {
                pageSize = AppConstants.Instance.DefaultPageSize;
            }


            X.PagedList.IPagedList <MembershipUser> users      = _membershipService.GetUsers(pageIndex.Value, pageSize.Value, search, orderby);
            MembershipUserListViewModel             userListVM = new MembershipUserListViewModel();

            userListVM.Search         = search;
            userListVM.OrderBy        = orderby;
            userListVM.MembershipList = users;
            return(View(userListVM));
        }
예제 #4
0
        public Select2DTO GetAirport(string q, int?page)
        {
            try
            {
                var query = db.Airport.AsQueryable();

                if (!String.IsNullOrWhiteSpace(q))
                {
                    query = query.Where(e =>
                                        e.Name.Contains(q) ||
                                        e.Icao.Contains(q) ||
                                        e.Iata.Contains(q));
                }
                X.PagedList.IPagedList <Airport> pagedAirports = query.ToPagedList(page ?? 1, 30);
                List <Select2ResultDTO>          result        = new List <Select2ResultDTO>();
                foreach (var item in pagedAirports)
                {
                    Select2ResultDTO temp = new Select2ResultDTO
                    {
                        id   = item.Id.ToString(),
                        text = $"{item.Name}"
                    };
                    result.Add(temp);
                }
                Select2PaginateDTO select2PaginateDTO = new Select2PaginateDTO
                {
                    more = pagedAirports.HasNextPage
                };
                Select2DTO select2DTO = new Select2DTO
                {
                    results  = result,
                    paginate = select2PaginateDTO,
                };
                return(select2DTO);
            }
            catch (Exception e)
            {
                throw;
            }
        }
예제 #5
0
        public IActionResult Sorting(string CurrentSort, string sort)
        {
            ViewBag.CurrentSort = sort;
            sort = string.IsNullOrEmpty(sort) ? "ProductId" : sort;
            sort = string.IsNullOrEmpty(sort) ? "ProductName" : sort;
            X.PagedList.IPagedList <Product> products = null;
            switch (sort)
            {
            case "ProductId":
                if (sort.Equals(CurrentSort))
                {
                    products = _context.Product.OrderByDescending(s => s.ProductId).ToPagedList();
                }
                else
                {
                    products = _context.Product.OrderBy(s => s.ProductId).ToPagedList();
                }
                break;

            case "ProductName":
                if (sort.Equals(CurrentSort))
                {
                    products = _context.Product.OrderByDescending(s => s.ProductName).ToPagedList();
                }
                else
                {
                    products = _context.Product.OrderBy(s => s.ProductName).ToPagedList();
                }
                break;

            default:

                products = _context.Product.OrderByDescending(s => s.ProductName).ToPagedList();
                break;
            }
            return(View(products));
        }