Skip to content

Instantly share code, notes, and snippets.

@mombrea
Created August 4, 2015 19:12
Show Gist options
  • Save mombrea/0d95b489b4ea1e63a8f7 to your computer and use it in GitHub Desktop.
Save mombrea/0d95b489b4ea1e63a8f7 to your computer and use it in GitHub Desktop.
public ActionResult Index(string sortOrder, string q, int page = 1, int pageSize = 25)
{
ViewBag.searchQuery = String.IsNullOrEmpty(q) ? "" : q;
page = page > 0 ? page : 1;
pageSize = pageSize > 0 ? pageSize : 25;
ViewBag.NameSortParam = sortOrder == "name" ? "name_desc" : "name";
ViewBag.AddressSortParam = sortOrder == "address" ? "address_desc" : "address";
ViewBag.DateSortParam = sortOrder == "date" ? "date_desc" : "date";
ViewBag.CurrentSort = sortOrder;
DataService service = new DateService(db);
var query = service.GetAllOrderedListItems(q);
switch (sortOrder)
{
case "name":
query = query.OrderBy(x => x.name);
break;
case "address":
query = query.OrderBy(x => x.address);
break;
case "address_desc":
query = query.OrderByDescending(x => x.address);
break;
case "date":
query = query.OrderBy(x => x.date);
break;
case "date_desc":
query = query.OrderByDescending(x => x.date);
break;
default:
break;
}
return View(query.ToPagedList(page, pageSize));
}
@joshuabaldwin
Copy link

Code review:

  1. Line 14 is clearly wrong. I believe that it is referring to System.Data.Services.DataServices but that class requires a type argument. In the same line, what is the "db" variable and where did it come from, since the documentation does not document the existence of a parameterized constructor for DataServices objects?

  2. There is no "GetAllOrderedListItems" method in the System.Data.Services.DataServices class.

  3. Switch statement does not establish a default sortOrder that will always be set, if the default option is selected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment