-
Notifications
You must be signed in to change notification settings - Fork 2
Grids #17
base: master
Are you sure you want to change the base?
Grids #17
Changes from 5 commits
29b00a4
c06914d
f026304
862e226
9bb53dd
efd14e0
ef9ae78
919f00c
e00afdb
fdaef85
b1ca711
f35209e
a11ff0b
5fd8850
76c592c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ | |
| /[Pp]ackages | ||
|
|
||
| *.user | ||
|
|
||
| /.idea | ||
| [Oo]bj | ||
| [Bb]in | ||
| /AssemblyVersion.cs | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| using System; | ||
| using System.Linq.Expressions; | ||
|
|
||
| namespace GraphLabs.Site.Core.Filters | ||
| { | ||
| public abstract class AbstractFilterableModel<T> | ||
| { | ||
| public static Expression<Func<T, bool>> CreateFilter(FilterParams filterParams) | ||
| { | ||
| return t => true; | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| using System; | ||
| using System.Collections.Specialized; | ||
|
|
||
| namespace GraphLabs.Site.Core.Filters | ||
| { | ||
| public class FilterParams | ||
| { | ||
| private readonly NameValueCollection _filterParams; | ||
|
|
||
| public FilterParams(NameValueCollection filterParams) | ||
| { | ||
| _filterParams = filterParams; | ||
| } | ||
|
|
||
| private string GetParam(string name) | ||
| { | ||
| string value = _filterParams.Get(name); | ||
| if (value == "") value = null; | ||
| return value; | ||
| } | ||
|
|
||
| public string GetStringParam(string name) | ||
| { | ||
| return GetParam(name); | ||
| } | ||
|
|
||
| public bool? GetBoolParam(string name) | ||
| { | ||
| string s = GetParam(name); | ||
| return s == null ? (bool?) null : Boolean.Parse(s); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| namespace GraphLabs.Site.Core.Filters | ||
| { | ||
| public interface IFilterAttribute | ||
| {} | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| using System; | ||
| using System.Linq.Expressions; | ||
| using GraphLabs.DomainModel.Infrastructure; | ||
| using GraphLabs.Site.Models.Infrastructure; | ||
|
|
||
| namespace GraphLabs.Site.Core.Filters | ||
| { | ||
| public interface IFilterable<TEntity, TModel> | ||
| where TEntity : AbstractEntity | ||
| where TModel : AbstractFilterableModel<TEntity> | ||
| { | ||
| IListModel<TModel> Filter(Expression<Func<TEntity, bool>> filter); | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| using System; | ||
|
|
||
| namespace GraphLabs.Site.Core.Filters | ||
| { | ||
| [System.AttributeUsage(System.AttributeTargets.Property)] | ||
| public class StringFilterAttribute : Attribute, IFilterAttribute | ||
| { | ||
| private string _name; | ||
|
|
||
| public StringFilterAttribute(string name) | ||
| { | ||
| _name = name; | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,21 +1,35 @@ | ||
| using System.Collections.Generic; | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq.Expressions; | ||
| using GraphLabs.DomainModel; | ||
| using GraphLabs.Site.Core.Filters; | ||
| using GraphLabs.Site.Models.Infrastructure; | ||
|
|
||
| namespace GraphLabs.Site.Models.Groups | ||
| { | ||
| public class GroupModel : IEntityBasedModel<Group> | ||
| public class GroupModel : AbstractFilterableModel<Group>, IEntityBasedModel<Group> | ||
| { | ||
| public long Id { get; set; } | ||
|
|
||
| [StringFilter("Номер группы")] | ||
| public string Name { get; set; } | ||
|
|
||
|
|
||
| [StringFilter("Возможность вступить в группу")] | ||
| public bool IsOpen { get; set; } | ||
|
|
||
| public ICollection<Student> Students { get; set; } | ||
|
|
||
| public int FirstYear { get; set; } | ||
|
|
||
| public int Number { get; set; } | ||
|
|
||
| public static Expression<Func<Group, bool>> CreateFilter(FilterParams filterParams) | ||
| { | ||
| string Name = filterParams.GetStringParam("Name"); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Name с маленькой буквы! |
||
| bool? isOpen = filterParams.GetBoolParam("IsOpen"); | ||
|
|
||
| return g => (Name == null || Name.Equals(g.Name)) | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. нужно сравнивать без учёта регистра |
||
| && (isOpen == null || g.IsOpen == isOpen); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| using System; | ||
| using System.Linq.Expressions; | ||
| using System.Web.Mvc; | ||
| using GraphLabs.DomainModel.Infrastructure; | ||
| using GraphLabs.Site.Core.Filters; | ||
| using GraphLabs.Site.Models.Infrastructure; | ||
|
|
||
| namespace GraphLabs.Site.Controllers | ||
| { | ||
| public abstract class GraphLabsFilteringController<TModel, TEntity> : GraphLabsController | ||
| where TEntity : AbstractEntity | ||
| where TModel : AbstractFilterableModel<TEntity>, IEntityBasedModel<TEntity> | ||
| { | ||
| protected Expression<Func<TEntity, bool>> _fiExpression; | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. С большой буквы, преобразовать в property { get; private set; } |
||
|
|
||
| protected override void OnActionExecuting(ActionExecutingContext filterContext) | ||
| { | ||
| if (filterContext.ActionDescriptor.ActionName.Equals("Index"))//может быть это ограничение лишнее | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. вместо Index надо nameof() |
||
| { | ||
| FilterParams _filterParams = new FilterParams(Request.QueryString); | ||
| _fiExpression = (Expression<Func<TEntity, bool>>) typeof(TModel).GetMethod("CreateFilter").Invoke(null, new[] {_filterParams}); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typeof(TModel).GetMethod()
|
||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| using GraphLabs.Site.Models.Infrastructure; | ||
|
|
||
| //namespace GraphLabs.Site.Filters | ||
| //{ | ||
| //// public interface IFilterableByName<TListModel, TModel> | ||
| //// where TListModel : IListModel<TModel> | ||
| //// { | ||
| //// TListModel FilterByName(string name); | ||
| //// } | ||
| //} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| using System; | ||
| using GraphLabs.DomainModel; | ||
| using GraphLabs.Site.Models.Infrastructure; | ||
|
|
||
| //namespace GraphLabs.Site.Filters | ||
| //{ | ||
| // public interface IFilterableByUserRole <TListModel, TModel> | ||
| // where TListModel : IListModel<TModel> | ||
| // { | ||
| // TListModel FilterByRole(UserRole role, bool isVerStudent, bool isUnVerStudent, bool isTeacher, bool isAdmin, bool isDismissStudent); | ||
| // } | ||
| //} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
вот тут получилась зависимость от конкретной dll, а должно быть от проекта