예제 #1
0
        public async Task OnGetAsync(string sortOrder, int? pageIndex)
        {
            NameSort = String.IsNullOrEmpty(sortOrder) ? "Name_desc" : "";
            DateSort = sortOrder == "Date" ? "Date_desc" : "Date";
            ViewsSort = sortOrder == "Views" ? "Views_desc" : "Views";
            IQueryable<RecipesModel> recipes = from s in _dbContext.Recipes
                                               select s;

            switch (sortOrder)
            {
                case "Name_desc":
                    recipes = recipes.OrderByDescending(s => s.Name);
                    break;
                case "Date":
                    recipes = recipes.OrderBy(s => s.Date);
                    break;
                case "Date_desc":
                    recipes = recipes.OrderByDescending(s => s.Date);
                    break;
                case "Views":
                    recipes = recipes.OrderBy(s => s.Views);
                    break;
                case "Views_desc":
                    recipes = recipes.OrderByDescending(s => s.Views);
                    break;
                default:
                    recipes = recipes.OrderBy(s => s.Name);
                    break;
            }
            int pageSize = 3;
            Recipes = await PaginateList<RecipesModel>.CreateAsync(
                recipes.AsNoTracking(), pageIndex ?? 1, pageSize) ;
        }
예제 #2
0
		public void 個数がページの大きさより小さいときはすべて返すテスト()
		{
			var list = new PaginateList<int>(4);
			list.AddShift(1);
			list.AddShift(2);
			list.AddShift(3);
			CollectionAssert.AreEqual(new[] { 1, 2, 3 }, (List<int>)list.GetPageContent());
		}
예제 #3
0
 public async Task<IActionResult> Index(int? pageNumber)
 {
     var posts = from s in _context.Posts
                 select s;
     int pageSize = 2;
     var paginate = await PaginateList<Post>.CreateAsync(posts.AsNoTracking(), pageNumber ?? 1, pageSize);
     return View(paginate);
 }
예제 #4
0
		public void Initialize()
		{
			pl = new PaginateList<int>(3);
			for (var i = 0; i < 10; i++)
			{
				pl.Add(i);
			}
		}
예제 #5
0
        public ActionResult Index(int?pageNumber)
        {
            QuotingSystemDbEntities db     = new QuotingSystemDbEntities();
            IEnumerable <Quote>     quotes = db.Quotes.ToList();

            int pageSize = 10;

            return(View(PaginateList <Quote> .Create(quotes, pageNumber ?? 1, pageSize)));
        }
예제 #6
0
        public async Task OnGetAsync(string sortOrder, string searchString, int?pageIndex)
        {
            NameSort = String.IsNullOrEmpty(sortOrder) ? "name_desc" : "";
            PostSort = sortOrder == "Post" ? "Post_desc" : "Post";
            RateSort = sortOrder == "Rate" ? "Rate_desc" : "Rate";
            if (searchString != null)
            {
                pageIndex = 1;
            }
            else
            {
                searchString = CurrentFilter;
            }
            CurrentFilter = searchString;

            IQueryable <UserModel> users = from s in _dbContext.Users
                                           select s;

            if (!String.IsNullOrEmpty(searchString))
            {
                users = users.Where(s => s.UserName.Contains(searchString));
            }
            switch (sortOrder)
            {
            case "name_desc":
                users = users.OrderByDescending(s => s.UserName);
                break;

            case "Post":
                users = users.OrderBy(s => s.Posts);
                break;

            case "Post_desc":
                users = users.OrderByDescending(s => s.Posts);
                break;

            case "Rate":
                users = users.OrderBy(s => s.UserRating);
                break;

            case "Rate_desc":
                users = users.OrderByDescending(s => s.UserRating);
                break;

            default:
                users = users.OrderBy(s => s.UserName);
                break;
            }
            int pageSize = 15;

            Persons = await PaginateList <UserModel> .CreateAsync(
                users.AsNoTracking(), pageIndex ?? 1, pageSize);
        }
예제 #7
0
		public void 追加して動くのテスト()
		{
			var list = new PaginateList<int>(4);
			list.AddShift(1);
			list.AddShift(2);
			list.AddShift(3);
			list.AddShift(4);
			CollectionAssert.AreEqual(new[] { 1,2,3,4 }, (List<int>)list.GetPageContent());
			list.AddShift(5);
			CollectionAssert.AreEqual(new[] { 2, 3, 4,5 }, (List<int>)list.GetPageContent());
			list.AddShift(6);
			list.AddShift(7);
			list.AddShift(8);
			list.AddShift(9);
			CollectionAssert.AreEqual(new[] {  6, 7 ,8,9}, (List<int>)list.GetPageContent());
			list.PrevPage();
			CollectionAssert.AreEqual(new[] {  2, 3, 4 ,5}, (List<int>)list.GetPageContent());




		}
        /// <inheritdoc/>
        public IPaginateEnumerable <T> Get <TKey>(Expression <Func <T, TKey> > keySelector, int pageIndex, int pageSize)
        {
            var query = GetQuery().OrderBy(keySelector).Skip(pageIndex * pageSize).Take(pageSize);

            return(PaginateList <T> .Create(query, pageIndex, pageSize, Count()));
        }
예제 #9
0
        public async Task <IActionResult> OnGetAsync(string UserId, string sortOrder, string searchString, int?pageIndex)
        {
            UserModel user;

            if (UserId == null)
            {
                user = await _userManager.GetUserAsync(User);
            }
            else
            {
                user = await _userManager.FindByIdAsync(UserId);
            }
            if (user == null)
            {
                return(RedirectToPage("/Error"));
            }
            if (User.Identity.Name != user.UserName && !User.IsInRole("admin"))
            {
                return(RedirectToPage("Account/AccessDenied"));
            }
            NameSort        = String.IsNullOrEmpty(sortOrder) ? "name_desc" : "";
            CategorySort    = sortOrder == "Category" ? "Category_desc" : "Category";
            ingredientsSort = sortOrder == "ingredients" ? "ingredients_desc" : "ingredients";
            DateSort        = sortOrder == "Date" ? "Date_desc" : "Date";
            RateSort        = sortOrder == "Rate" ? "Rate_desc" : "Rate";
            if (searchString != null)
            {
                pageIndex = 1;
            }
            else
            {
                searchString = CurrentFilter;
            }
            CurrentFilter = searchString;
            IQueryable <RecipesModel> recipes = from s in _dbContext.Recipes
                                                select s;

            if (!String.IsNullOrEmpty(searchString))
            {
                recipes = recipes.Where(s => s.Name.Contains(searchString) ||
                                        s.CategoryName.Contains(searchString) ||
                                        s.Date.Contains(searchString));
            }
            switch (sortOrder)
            {
            case "name_desc":
                recipes = recipes.OrderByDescending(s => s.Name);
                break;

            case "Category":
                recipes = recipes.OrderBy(s => s.CategoryName);
                break;

            case "Category_desc":
                recipes = recipes.OrderByDescending(s => s.CategoryName);
                break;

            case "ingredients":
                recipes = recipes.OrderBy(s => s.Ingredients);
                break;

            case "ingredients_desc":
                recipes = recipes.OrderByDescending(s => s.Ingredients);
                break;

            case "Date":
                recipes = recipes.OrderBy(s => s.Date);
                break;

            case "Date_desc":
                recipes = recipes.OrderByDescending(s => s.Date);
                break;

            case "Rate":
                recipes = recipes.OrderBy(s => s.Rating);
                break;

            case "Rate_desc":
                recipes = recipes.OrderByDescending(s => s.Rating);
                break;

            default:
                recipes = recipes.OrderBy(s => s.Name);
                break;
            }
            Id = user.Id;
            int pageSize = 3;

            Recipes = await PaginateList <RecipesModel> .CreateAsync(
                recipes.Where(o => o.UserId == user.Id).AsNoTracking(), pageIndex ?? 1, pageSize);

            return(Page());
        }
예제 #10
0
        public Task <PaginateList <WeekEntity> > paginateWeeks(int?page)
        {
            var weeks = db.OrderByDescending(w => w.EndTime).AsQueryable();

            return(PaginateList <WeekEntity> .CreateAsync(weeks, page ?? 1, 54));
        }