VEU.WathBody/3-app/1-lib/Kit.Helpers/Repository/Paging/PagingByPage.cs

73 lines
2.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Linq;
namespace Kit.Helpers.Repository.Paging
{
/// <summary>
/// Фильтр с полями постраничной фильтрации.
/// <para>Применяется, например в PagingController</para>
/// </summary>
public class PagingByPage : IPageFilter
{
public int? Start { get; set; }
public int? Lenght { get; set; }
public string SortColumnName { get; set; }
public string SortDirection { get; set; }
public string Tabs { get; set; }
public string pageParameterId { get; set; }
/// <summary>
/// Номер страницы. Нумерация с 1-цы
/// </summary>
public int? PageNo { get; set; }
public int? PageSize { get; set; }
public int? TotalRows { get; set; }
public int? CountPages { get; set; }
/// <summary>
/// Есть значения для разбиения на страницы
/// </summary>
public bool HasSize
{
get
{
return
this.PageNo.HasValue &&
(this.PageNo > 0) &&
this.PageSize.HasValue &&
(this.PageSize > 0);
}
}
public string FormId
{
get
{
return _formId;
}
set
{
_formId = value;
}
}
public IQueryable<TEntity> ChangePage<TEntity>(IQueryable<TEntity> query)
{
if (query == null) return null;
if (!(this.PageNo.HasValue && this.PageSize.HasValue)) return query;
return query.Skip((this.PageNo.Value - 1) * this.PageSize.Value).Take(this.PageSize.Value);
}
#region Fields ---------------------------------------
/// <summary>
/// Для передачи в частичное представление Id формы, которая владеет просмотром страниц
/// </summary>
private string _formId = "";
#endregion
}
}