MarlabsInc/SocialGoal — pull request #6 by PeterKneale (2014-02-01 02:09:17+00:00)
Title: Introducted IPagedList for simplified paging and changed the GroupList p...

Added one more method to the repository to enable easy paging
```
public virtual IPagedList GetPage(Page page, Expression> where, Expression> order)
{
var results = dbset.OrderBy(order).Where(where).GetPage(page).ToList();
var total = dbset.Count(where);
return new StaticPagedList(results, page.PageNumber, page.PageSize, total);
}
```

Updated the service layer to use the new repository methods
```
public IPagedList GetGroups(string userId, string filterBy, Page page)
{
switch (filterBy)
{
case "All":
{
return groupRepository.GetPage(page,x=>true,order=>order.GroupName);
}
case "My Groups":
{
var groupsIds = groupUserrepository.GetMany(gru => gru.UserId == userId && gru.Admin).Select(gru => gru.GroupId);
return groupRepository.GetPage(page, where => groupsIds.Contains(where.GroupId), order => order.CreatedDate);
}
...
default:
{
throw new ApplicationException("Filter not understood");
}
}
}
```

Updated GroupList page to use it. Much less javascript code, just one line now to have clean ajax paging.
```

@Html.Partial("_GroupsTable", Model)

```

Setup Automapper to map Paged Lists of models.
```
Mapper.CreateMap, IPagedList>().ConvertUsing>();
```

Used PagedList.MVC to rendering paging controls. Use the Ajax rendering option so that a partial is called and rendered in place.
```
@if (Model.GroupList.Any())
{

@Html.Partial("_GroupsTableRows", Model.GroupList)

@Html.PagedListPager(
Model.GroupList,
page => Url.Action("GroupList",
new { page, filterBy = Model.SelectedFilter }),
PagedListRenderOptions.EnableUnobtrusiveAjaxReplacing(new AjaxOptions { UpdateTargetId = "GroupPagingContainer" })
)
}
else
{
@Html.Partial("_AlertInfo", "No groups found");
}
```
Sorry not sure why its saying I'm modifying the whole file, I've only adjusted a few lines in the Repo to add one new method and in the group service I just adjusted the one method. Maybe out linefeed settings are different.