Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace AjaxPaging.Models
  6. {
  7.     public class PersonRepository
  8.     {
  9.         private static readonly IList<Person> Persons = new List<Person>();
  10.  
  11.         public PersonRepository()
  12.         {
  13.             if (Persons.Count == 0)
  14.             {
  15.                 for (var i = 1; i < 1000; i++)
  16.                 {
  17.                     var p = new Person() { Id = i, Name = Guid.NewGuid().ToString() };
  18.                     Persons.Add(p);
  19.                 }
  20.             }
  21.         }
  22.  
  23.         public IList<Person> Get(int page, out int total)
  24.         {
  25.             var persons = (from p in Persons select p).Skip((page - 1) * 10).Take(10);
  26.             var totalPerson = (from p in Persons select p).Count();
  27.             total = totalPerson / 10 + (totalPerson % 10 > 0 ? 1 : 0);
  28.             return persons.ToList();
  29.         }
  30.  
  31.         public IList<Person> Get(int page, string criteria, out int total)
  32.         {
  33.             var persons = (from p in Persons where p.Name.StartsWith(criteria) select p).Skip((page - 1) * 10).Take(10);
  34.             var totalPerson = (from p in Persons select p).Count();
  35.             total = totalPerson / 10 + (totalPerson % 10 > 0 ? 1 : 0);
  36.             return persons.ToList();
  37.  
  38.         }
  39.  
  40.     }
  41. }
  42.