- MvcMusicStore_WebGrid.zip
- MvcMusicStore
- MvcMusicStore.sln
- MvcMusicStore.suo
- MvcMusicStore
- App_Data
- MvcMusicStore.mdf
- MvcMusicStore_log.ldf
- Common
- Content
- images
- arrow_down.png
- arrow_up.png
- bullet.gif
- button-bg.jpg
- clock.gif
- comment.gif
- content.jpg
- dots.jpg
- firefox-gray.jpg
- footer.jpg
- header.jpg
- menu.jpg
- page.gif
- quote.gif
- square-green.png
- Site.css
- themes
- base
- images
- ui-bg_flat_0_aaaaaa_40x100.png
- ui-bg_flat_75_ffffff_40x100.png
- ui-bg_glass_55_fbf9ee_1x400.png
- ui-bg_glass_65_ffffff_1x400.png
- ui-bg_glass_75_dadada_1x400.png
- ui-bg_glass_75_e6e6e6_1x400.png
- ui-bg_glass_95_fef1ec_1x400.png
- ui-bg_highlight-soft_75_cccccc_1x100.png
- ui-icons_222222_256x240.png
- ui-icons_2e83ff_256x240.png
- ui-icons_454545_256x240.png
- ui-icons_888888_256x240.png
- ui-icons_cd0a0a_256x240.png
- jquery-ui.css
- Controllers
- Global.asax
- Global.asax.cs
- Models
- MvcMusicStore.csproj
- MvcMusicStore.csproj.user
- Properties
- Scripts
- Views
- Web.config
- Web.Debug.config
- Web.Release.config
- Reference
- MvcContrib.dll
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Web.Mvc;
using MvcContrib.Pagination;
using MvcContrib.UI.Grid;
using MvcContrib.Sorting;
using MvcMusicStore.Common;
namespace MvcMusicStore.Models
{
public class PagedViewModel<T>
{
public ViewDataDictionary ViewData { get; set; }
public IQueryable<T> Query { get; set; }
public GridSortOptions GridSortOptions { get; set; }
public string DefaultSortColumn { get; set; }
public IPagination<T> PagedList { get; private set; }
public int? Page { get; set; }
public int? PageSize { get; set; }
public PagedViewModel<T> AddFilter(Expression<Func<T, bool>> predicate)
{
Query = Query.Where(predicate);
return this;
}
public PagedViewModel<T> AddFilter<TValue>(string key, TValue value, Expression<Func<T, bool>> predicate)
{
ProcessQuery(value, predicate);
ViewData[key] = value;
return this;
}
public PagedViewModel<T> AddFilter<TValue>(string keyField, object value, Expression<Func<T, bool>> predicate,
IQueryable<TValue> query, string textField)
{
ProcessQuery(value, predicate);
var selectList = query.ToSelectList(keyField, textField, value);
ViewData[keyField] = selectList;
return this;
}
public PagedViewModel<T> Setup()
{
if (string.IsNullOrWhiteSpace(GridSortOptions.Column))
{
GridSortOptions.Column = DefaultSortColumn;
}
PagedList = Query.OrderBy(GridSortOptions.Column, GridSortOptions.Direction)
.AsPagination(Page ?? 1, PageSize ?? 10);
return this;
}
private void ProcessQuery<TValue>(TValue value, Expression<Func<T, bool>> predicate)
{
if (value == null) return;
if (typeof(TValue) == typeof(string))
{
if (string.IsNullOrWhiteSpace(value as string)) return;
}
Query = Query.Where(predicate);
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.