Hi Destinykid,
Change the GetCustomers method with below.
private CustomerModel GetCustomers(int currentPage)
{
int maxRows = 10;
CustomerModel customerModel = new CustomerModel();
customerModel.Customers = PopulateCustomers()
.OrderBy(x => x.CustomerID)
.Skip((currentPage - 1) * maxRows)
.Take(maxRows).ToList();
double pageCount = (double)((decimal)PopulateCustomers().Count() / Convert.ToDecimal(maxRows));
customerModel.PageCount = (int)Math.Ceiling(pageCount);
customerModel.CurrentPageIndex = currentPage;
return customerModel;
}
private static List<Customer> PopulateCustomers()
{
string constr = @"Data Source=.;Initial Catalog=Northwind;uid=sa;pwd=pass@123;";
List<Customer> customers = new List<Customer>();
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SELECT CustomerID,ContactName,City,Country FROM Customers"))
{
cmd.Connection = con;
con.Open();
using (SqlDataReader sdr = cmd.ExecuteReader())
{
while (sdr.Read())
{
customers.Add(new Customer
{
CustomerID = sdr["CustomerID"].ToString(),
ContactName = sdr["ContactName"].ToString(),
City = sdr["City"].ToString(),
Country = sdr["Country"].ToString(),
});
}
}
con.Close();
}
}
return customers;
}