Skip to content
This repository was archived by the owner on Jun 7, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/[Pp]ackages

*.user

/.idea
[Oo]bj
[Bb]in
/AssemblyVersion.cs
Expand Down
4 changes: 2 additions & 2 deletions GraphLabs.Dal.Ef/GraphLabs.Dal.Ef.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PreBuildEvent>cd "$(SolutionDir)"
powershell "&amp; ""$(SolutionDir)\generateVersionInfo.ps1"""</PreBuildEvent>
<!--<PreBuildEvent>cd "$(SolutionDir)"-->
<!--powershell "&amp; ""$(SolutionDir)\generateVersionInfo.ps1"""</PreBuildEvent>-->
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
4 changes: 2 additions & 2 deletions GraphLabs.DomainModel/GraphLabs.DomainModel.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,8 @@
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PreBuildEvent>cd "$(SolutionDir)"
powershell "&amp; ""$(SolutionDir)\generateVersionInfo.ps1"""</PreBuildEvent>
<!--<PreBuildEvent>cd "$(SolutionDir)"-->
<!--powershell "&amp; ""$(SolutionDir)\generateVersionInfo.ps1"""</PreBuildEvent>-->
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
13 changes: 13 additions & 0 deletions GraphLabs.Site.Core/Filters/AbstractFilterableModel.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;
}
}
}
33 changes: 33 additions & 0 deletions GraphLabs.Site.Core/Filters/FilterParams.cs
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);
}
}
}
5 changes: 5 additions & 0 deletions GraphLabs.Site.Core/Filters/IFilterAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace GraphLabs.Site.Core.Filters
{
public interface IFilterAttribute
{}
}
15 changes: 15 additions & 0 deletions GraphLabs.Site.Core/Filters/IFilterable.cs
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);
}

}
15 changes: 15 additions & 0 deletions GraphLabs.Site.Core/Filters/StringFilterAttribute.cs
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;
}
}
}
15 changes: 13 additions & 2 deletions GraphLabs.Site.Core/GraphLabs.Site.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@
<CodeContractsAnalysisWarningLevel>0</CodeContractsAnalysisWarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="GraphLabs.DomainModel, Version=0.1.0.461, Culture=neutral, PublicKeyToken=null">

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

вот тут получилась зависимость от конкретной dll, а должно быть от проекта

<HintPath>..\GraphLabs.WcfServices\Bin\GraphLabs.DomainModel.dll</HintPath>
</Reference>
<Reference Include="GraphLabs.Site.Models, Version=0.1.0.461, Culture=neutral, PublicKeyToken=null">
<HintPath>..\GraphLabs.WcfServices\Bin\GraphLabs.Site.Models.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
Expand All @@ -135,6 +141,11 @@
<Compile Include="..\AssemblyVersion.cs">
<Link>Properties\AssemblyVersion.cs</Link>
</Compile>
<Compile Include="Filters\FilterParams.cs" />
<Compile Include="Filters\AbstractFilterableModel.cs" />
<Compile Include="Filters\IFilterAttribute.cs" />
<Compile Include="Filters\IFilterable.cs" />
<Compile Include="Filters\StringFilterAttribute.cs" />
<Compile Include="GraphLabsException.cs" />
<Compile Include="IChangesTracker.cs" />
<Compile Include="OperationContext\IOperationContext.cs" />
Expand All @@ -144,8 +155,8 @@
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PreBuildEvent>cd "$(SolutionDir)"
powershell "&amp; ""$(SolutionDir)\generateVersionInfo.ps1"""</PreBuildEvent>
<!--<PreBuildEvent>cd "$(SolutionDir)"-->
<!--powershell "&amp; ""$(SolutionDir)\generateVersionInfo.ps1"""</PreBuildEvent>-->
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
4 changes: 2 additions & 2 deletions GraphLabs.Site.Logic/GraphLabs.Site.Logic.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PreBuildEvent>cd "$(SolutionDir)"
powershell "&amp; ""$(SolutionDir)\generateVersionInfo.ps1"""</PreBuildEvent>
<!--<PreBuildEvent>cd "$(SolutionDir)"-->
<!--powershell "&amp; ""$(SolutionDir)\generateVersionInfo.ps1"""</PreBuildEvent>-->
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
5 changes: 2 additions & 3 deletions GraphLabs.Site.Models/GraphLabs.Site.Models.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,10 @@
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PreBuildEvent>cd "$(SolutionDir)"
powershell "&amp; ""$(SolutionDir)\generateVersionInfo.ps1"""</PreBuildEvent>
<!--<PreBuildEvent>cd "$(SolutionDir)"-->
<!--powershell "&amp; ""$(SolutionDir)\generateVersionInfo.ps1"""</PreBuildEvent>-->
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
15 changes: 13 additions & 2 deletions GraphLabs.Site.Models/Groups/GroupListModel.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
using System.Linq;
using System;
using System.Linq;
using System.Linq.Expressions;
using GraphLabs.DomainModel;
using GraphLabs.Site.Core.Filters;
using GraphLabs.Site.Models.Infrastructure;

namespace GraphLabs.Site.Models.Groups
{
/// <summary> Модель списка групп </summary>
public sealed class GroupListModel : ListModelBase<GroupModel>
public sealed class GroupListModel : ListModelBase<GroupModel>, IFilterable<Group, GroupModel>
{
private readonly IEntityQuery _query;
private readonly IEntityBasedModelLoader<GroupModel, Group> _modelLoader;
private Expression<Func<Group, bool>> _filter = (group => true);

/// <summary> Модель списка групп </summary>
public GroupListModel(IEntityQuery query, IEntityBasedModelLoader<GroupModel, Group> modelLoader)
Expand All @@ -21,9 +25,16 @@ public GroupListModel(IEntityQuery query, IEntityBasedModelLoader<GroupModel, Gr
protected override GroupModel[] LoadItems()
{
return _query.OfEntities<Group>()
.Where(_filter)
.ToArray()
.Select(_modelLoader.Load)
.ToArray();
}

public IListModel<GroupModel> Filter(Expression<Func<Group, bool>> filter)
{
_filter = filter;
return this;
}
}
}
20 changes: 17 additions & 3 deletions GraphLabs.Site.Models/Groups/GroupModel.cs
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");

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The 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))

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

нужно сравнивать без учёта регистра

&& (isOpen == null || g.IsOpen == isOpen);
}
}
}
2 changes: 1 addition & 1 deletion GraphLabs.Site.Models/Schedule/LabScheduleListModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace GraphLabs.Site.Models.Schedule
{
/// <summary> ������ ���������� (������) </summary>
/// <summary> Модель расписания (списка) </summary>
public class LabScheduleListModel : ListModelBase<LabScheduleModel>
{
private readonly IEntityQuery _query;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PreBuildEvent>cd "$(SolutionDir)"
powershell "&amp; ""$(SolutionDir)\generateVersionInfo.ps1"""</PreBuildEvent>
<!--<PreBuildEvent>cd "$(SolutionDir)"-->
<!--powershell "&amp; ""$(SolutionDir)\generateVersionInfo.ps1"""</PreBuildEvent>-->
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
25 changes: 25 additions & 0 deletions GraphLabs.Site/Controllers/GraphLabsFilteringController.cs
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;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The 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"))//может быть это ограничение лишнее

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The 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});

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typeof(TModel).GetMethod()

  • надо закешировать
  • и снова nameof

}
}
}
}
11 changes: 5 additions & 6 deletions GraphLabs.Site/Controllers/GroupController.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using GraphLabs.Site.Controllers.Attributes;
using System.Web.Mvc;
using System.Web.Mvc;
using GraphLabs.DomainModel;
using GraphLabs.Site.Controllers.Attributes;
using GraphLabs.Site.Models.Groups;
using GraphLabs.Site.Models.Infrastructure;

namespace GraphLabs.Site.Controllers
{
[GLAuthorize(UserRole.Administrator, UserRole.Teacher)]
public class GroupController : GraphLabsController
public class GroupController : GraphLabsFilteringController<GroupModel, Group>
{
private readonly IListModelLoader _listModelLoader;
private readonly IEntityBasedModelSaver<GroupModel, Group> _modelSaver;
Expand All @@ -26,9 +26,8 @@ public GroupController(
public ActionResult Index(string message)
{
ViewBag.Message = message;

var model = _listModelLoader.LoadListModel<GroupListModel, GroupModel>();
return View(model);
var model = _listModelLoader.LoadListModel<GroupListModel, GroupModel>().Filter(_fiExpression);
return View((GroupListModel) model);
}

public ActionResult Create()
Expand Down
10 changes: 10 additions & 0 deletions GraphLabs.Site/Filters/IFilterableByName.cs
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);
//// }
//}
12 changes: 12 additions & 0 deletions GraphLabs.Site/Filters/IFilterableByUserRole.cs
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);
// }
//}
8 changes: 5 additions & 3 deletions GraphLabs.Site/GraphLabs.Site.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Controllers\GraphLabsFilteringController.cs" />
<Compile Include="Views\Helpers\GraphLabsUIFactory.cs" />
<Compile Include="Views\Helpers\GraphLabsWebGrid.cs" />
<Content Include="Content\bootstrap-theme.css" />
<Content Include="Content\bootstrap-theme.min.css" />
<Content Include="Content\bootstrap.css" />
Expand Down Expand Up @@ -529,7 +532,6 @@
</ItemGroup>
<ItemGroup>
<Folder Include="App_Data\" />
<Folder Include="Filters\" />
</ItemGroup>
<ItemGroup>
<Content Include="packages.config" />
Expand Down Expand Up @@ -600,8 +602,8 @@
</VisualStudio>
</ProjectExtensions>
<PropertyGroup>
<PreBuildEvent>cd "$(SolutionDir)"
powershell "&amp; ""$(SolutionDir)\generateVersionInfo.ps1"""</PreBuildEvent>
<!--<PreBuildEvent>cd "$(SolutionDir)"-->
<!--powershell "&amp; ""$(SolutionDir)\generateVersionInfo.ps1"""</PreBuildEvent>-->
</PropertyGroup>
<Target Name="BeforeBuild" Condition="'$(PublishProfileName)' == '' And '$(WebPublishProfileFile)' == ''">
<TransformXml Source="Web.Base.config" Transform="Web.$(Configuration).config" Destination="Web.config" />
Expand Down
Loading