Created
August 4, 2015 19:12
-
-
Save mombrea/0d95b489b4ea1e63a8f7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Code review:
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?
There is no "GetAllOrderedListItems" method in the System.Data.Services.DataServices class.
Switch statement does not establish a default sortOrder that will always be set, if the default option is selected.