56 lines
2.0 KiB
C#
56 lines
2.0 KiB
C#
namespace LaaProductionWeb.Services.Models
|
|
{
|
|
using System;
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
using System.Linq.Expressions;
|
|
using System.Reflection;
|
|
|
|
public enum PropertyType
|
|
{
|
|
Text,
|
|
Date,
|
|
Bool
|
|
}
|
|
|
|
public static class HeliumReportModelExtensions
|
|
{
|
|
|
|
public static HeliumReportFilterProperty Text(this HeliumReportItem model, Expression<Func<HeliumReportItem, object>> expression, int index, int orderBy = 0)
|
|
=> model.Property(expression, index, PropertyType.Text, orderBy);
|
|
|
|
public static HeliumReportFilterProperty DateTime(this HeliumReportItem model, Expression<Func<HeliumReportItem, object>> expression, int index, int orderBy = 0)
|
|
=> model.Property(expression, index, PropertyType.Date, orderBy);
|
|
|
|
public static HeliumReportFilterProperty Boolean(this HeliumReportItem model, Expression<Func<HeliumReportItem, object>> expression, int index, int orderBy = 0)
|
|
=> model.Property(expression, index, PropertyType.Bool, orderBy);
|
|
|
|
public static HeliumReportFilterProperty Property(
|
|
this HeliumReportItem model
|
|
, Expression<Func<HeliumReportItem, object>> expression
|
|
, int index
|
|
, PropertyType propertyType
|
|
, int orderBy)
|
|
{
|
|
var memberInfo = default(MemberInfo);
|
|
|
|
if (expression.Body is MemberExpression memberExpression)
|
|
{
|
|
memberInfo = memberExpression.Member;
|
|
}
|
|
else if (expression.Body is UnaryExpression unaryExpression && unaryExpression.Operand is MemberExpression operandExpression)
|
|
{
|
|
memberInfo = operandExpression.Member;
|
|
}
|
|
|
|
return new HeliumReportFilterProperty
|
|
{
|
|
Column = memberInfo?.GetCustomAttribute<ColumnAttribute>()?.Name,
|
|
Property = memberInfo?.Name,
|
|
OrderBy = orderBy,
|
|
Index = index,
|
|
Type = propertyType
|
|
};
|
|
}
|
|
}
|
|
}
|