Skip to content

Commit

Permalink
Normalized line endings
Browse files Browse the repository at this point in the history
  • Loading branch information
martijnboland committed Apr 14, 2014
1 parent 438459d commit 31c1339
Show file tree
Hide file tree
Showing 29 changed files with 5,216 additions and 5,216 deletions.
196 changes: 98 additions & 98 deletions src/MvcPaging.Demo/Controllers/PagingController.cs
Original file line number Diff line number Diff line change
@@ -1,99 +1,99 @@
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using MvcPaging.Demo.Models;

namespace MvcPaging.Demo.Controllers
{
public class PagingController : Controller
{
private const int DefaultPageSize = 10;
private IList<Product> allProducts = new List<Product>();
private readonly string[] allCategories = new string[3] { "Shoes", "Electronics", "Food" };

public PagingController()
{
InitializeProducts();
}

private void InitializeProducts()
{
// Create a list of products. 50% of them are in the Shoes category, 25% in the Electronics
// category and 25% in the Food category.
for (var i = 0; i < 527; i++)
{
var product = new Product();
product.Name = "Product " + (i + 1);
var categoryIndex = i % 4;
if (categoryIndex > 2)
{
categoryIndex = categoryIndex - 3;
}
product.Category = allCategories[categoryIndex];
allProducts.Add(product);
}
}

public ActionResult Index(int? page)
{
int currentPageIndex = page.HasValue ? page.Value - 1 : 0;
return View(this.allProducts.ToPagedList(currentPageIndex, DefaultPageSize));
}

public ActionResult CustomPageRouteValueKey(SearchModel search)
{
int currentPageIndex = search.page.HasValue ? search.page.Value - 1 : 0;
return View(this.allProducts.ToPagedList(currentPageIndex, DefaultPageSize));
}

public ActionResult ViewByCategory(string categoryName, int? page)
{
categoryName = categoryName ?? this.allCategories[0];
int currentPageIndex = page.HasValue ? page.Value - 1 : 0;

var productsByCategory = this.allProducts.Where(p => p.Category.Equals(categoryName)).ToPagedList(currentPageIndex,
DefaultPageSize);
ViewBag.CategoryName = new SelectList(this.allCategories, categoryName);
ViewBag.CategoryDisplayName = categoryName;
return View("ProductsByCategory", productsByCategory);
}

public ActionResult ViewByCategories(string[] categories, int? page)
{
var model = new ViewByCategoriesViewModel();
model.Categories = categories ?? new string[0];
int currentPageIndex = page.HasValue ? page.Value - 1 : 0;

model.Products = this.allProducts.Where(p => model.Categories.Contains(p.Category)).ToPagedList(currentPageIndex, DefaultPageSize);
model.AvailableCategories = this.allCategories;
return View("ProductsByCategories", model);
}

public ActionResult IndexAjax()
{
int currentPageIndex = 0;
var products = this.allProducts.ToPagedList(currentPageIndex, DefaultPageSize);
return View(products);
}

public ActionResult AjaxPage(int? page)
{
ViewBag.Title = "Browse all products";
int currentPageIndex = page.HasValue ? page.Value - 1 : 0;
var products = this.allProducts.ToPagedList(currentPageIndex, DefaultPageSize);
return PartialView("_ProductGrid", products);
}

public ActionResult Bootstrap(int? page)
{
int currentPageIndex = page.HasValue ? page.Value - 1 : 0;
return View(this.allProducts.ToPagedList(currentPageIndex, DefaultPageSize));
}

public ActionResult Bootstrap3(int? page)
{
int currentPageIndex = page.HasValue ? page.Value - 1 : 0;
return View(this.allProducts.ToPagedList(currentPageIndex, DefaultPageSize));
}
}
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using MvcPaging.Demo.Models;

namespace MvcPaging.Demo.Controllers
{
public class PagingController : Controller
{
private const int DefaultPageSize = 10;
private IList<Product> allProducts = new List<Product>();
private readonly string[] allCategories = new string[3] { "Shoes", "Electronics", "Food" };

public PagingController()
{
InitializeProducts();
}

private void InitializeProducts()
{
// Create a list of products. 50% of them are in the Shoes category, 25% in the Electronics
// category and 25% in the Food category.
for (var i = 0; i < 527; i++)
{
var product = new Product();
product.Name = "Product " + (i + 1);
var categoryIndex = i % 4;
if (categoryIndex > 2)
{
categoryIndex = categoryIndex - 3;
}
product.Category = allCategories[categoryIndex];
allProducts.Add(product);
}
}

public ActionResult Index(int? page)
{
int currentPageIndex = page.HasValue ? page.Value - 1 : 0;
return View(this.allProducts.ToPagedList(currentPageIndex, DefaultPageSize));
}

public ActionResult CustomPageRouteValueKey(SearchModel search)
{
int currentPageIndex = search.page.HasValue ? search.page.Value - 1 : 0;
return View(this.allProducts.ToPagedList(currentPageIndex, DefaultPageSize));
}

public ActionResult ViewByCategory(string categoryName, int? page)
{
categoryName = categoryName ?? this.allCategories[0];
int currentPageIndex = page.HasValue ? page.Value - 1 : 0;

var productsByCategory = this.allProducts.Where(p => p.Category.Equals(categoryName)).ToPagedList(currentPageIndex,
DefaultPageSize);
ViewBag.CategoryName = new SelectList(this.allCategories, categoryName);
ViewBag.CategoryDisplayName = categoryName;
return View("ProductsByCategory", productsByCategory);
}

public ActionResult ViewByCategories(string[] categories, int? page)
{
var model = new ViewByCategoriesViewModel();
model.Categories = categories ?? new string[0];
int currentPageIndex = page.HasValue ? page.Value - 1 : 0;

model.Products = this.allProducts.Where(p => model.Categories.Contains(p.Category)).ToPagedList(currentPageIndex, DefaultPageSize);
model.AvailableCategories = this.allCategories;
return View("ProductsByCategories", model);
}

public ActionResult IndexAjax()
{
int currentPageIndex = 0;
var products = this.allProducts.ToPagedList(currentPageIndex, DefaultPageSize);
return View(products);
}

public ActionResult AjaxPage(int? page)
{
ViewBag.Title = "Browse all products";
int currentPageIndex = page.HasValue ? page.Value - 1 : 0;
var products = this.allProducts.ToPagedList(currentPageIndex, DefaultPageSize);
return PartialView("_ProductGrid", products);
}

public ActionResult Bootstrap(int? page)
{
int currentPageIndex = page.HasValue ? page.Value - 1 : 0;
return View(this.allProducts.ToPagedList(currentPageIndex, DefaultPageSize));
}

public ActionResult Bootstrap3(int? page)
{
int currentPageIndex = page.HasValue ? page.Value - 1 : 0;
return View(this.allProducts.ToPagedList(currentPageIndex, DefaultPageSize));
}
}
}
26 changes: 13 additions & 13 deletions src/MvcPaging.Demo/Models/ViewByCategoriesViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace MvcPaging.Demo.Models
{
public class ViewByCategoriesViewModel
{
public IPagedList<Product> Products { get; set; }
public string[] AvailableCategories { get; set; }
public string[] Categories { get; set; }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace MvcPaging.Demo.Models
{
public class ViewByCategoriesViewModel
{
public IPagedList<Product> Products { get; set; }
public string[] AvailableCategories { get; set; }
public string[] Categories { get; set; }
}
}
14 changes: 7 additions & 7 deletions src/MvcPaging.Demo/Models/ViewSourceViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
namespace MvcPaging.Demo.Models
{
public class ViewSourceViewModel
{
public string RazorCode { get; set; }
public string ControllerCode { get; set; }
}
namespace MvcPaging.Demo.Models
{
public class ViewSourceViewModel
{
public string RazorCode { get; set; }
public string ControllerCode { get; set; }
}
}
Loading

0 comments on commit 31c1339

Please sign in to comment.