Moves templatequery models into the right folder

This commit is contained in:
per ploug
2014-06-26 11:24:57 +02:00
parent 4fea55e751
commit 8a93c8371c
11 changed files with 11 additions and 17 deletions

View File

@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Umbraco.Web.Models.TemplateQuery
{
public class ContentTypeModel
{
public string Alias { get; set; }
public string Name { get; set; }
}
}

View File

@@ -0,0 +1,14 @@
namespace Umbraco.Web.Models.TemplateQuery
{
public enum Operathor
{
Equals = 1,
NotEquals = 2,
Contains = 3,
NotContains = 4,
LessThan = 5,
LessThanEqualTo = 6,
GreaterThan = 7,
GreaterThanEqualTo = 8
}
}

View File

@@ -0,0 +1,25 @@
using System.Collections.Generic;
namespace Umbraco.Web.Models.TemplateQuery
{
public class OperathorTerm
{
public OperathorTerm()
{
Name = "is";
Operathor = Operathor.Equals;
AppliesTo = new [] { "string" };
}
public OperathorTerm(string name, Operathor operathor, IEnumerable<string> appliesTo)
{
Name = name;
Operathor = operathor;
AppliesTo = appliesTo;
}
public string Name { get; set; }
public Operathor Operathor { get; set; }
public IEnumerable<string> AppliesTo { get; set; }
}
}

View File

@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Umbraco.Web.Models.TemplateQuery
{
public class PropertyModel
{
public string Name { get; set; }
public string Alias { get; set; }
public string Type { get; set; }
}
}

View File

@@ -0,0 +1,60 @@
namespace Umbraco.Web.Models.TemplateQuery
{
public class QueryCondition
{
public PropertyModel Property { get; set; }
public OperathorTerm Term { get; set; }
public string ConstraintValue { get; set; }
}
internal static class QueryConditionExtensions
{
private static string MakeBinaryOperation(this QueryCondition condition, string operand, int token)
{
return string.Format("{0}{1}@{2}", condition.Property.Name, operand, token);
}
public static string BuildCondition(this QueryCondition condition, int token)
{
var operand = string.Empty;
var value = string.Empty;
switch (condition.Term.Operathor)
{
case Operathor.Equals:
operand = " == ";
break;
case Operathor.NotEquals:
operand = " != ";
break;
case Operathor.GreaterThan:
operand = " > ";
break;
case Operathor.GreaterThanEqualTo:
operand = " >= ";
break;
case Operathor.LessThan:
operand = " < ";
break;
case Operathor.LessThanEqualTo:
operand = " <= ";
break;
case Operathor.Contains:
value = string.Format("{0}.Contains(@{1})", condition.Property.Name, token);
break;
case Operathor.NotContains:
value = string.Format("!{0}.Contains(@{1})", condition.Property.Name, token);
break;
default :
operand = " == ";
break;
}
return string.IsNullOrEmpty(value) ? condition.MakeBinaryOperation(operand, token) : value;
}
}
}

View File

@@ -0,0 +1,13 @@
using System.Collections.Generic;
namespace Umbraco.Web.Models.TemplateQuery
{
public class QueryModel
{
public ContentTypeModel ContentType { get; set; }
public SourceModel Source { get; set; }
public IEnumerable<QueryCondition> Filters { get; set; }
public SortExpression Sort { get; set; }
public int Take { get; set; }
}
}

View File

@@ -0,0 +1,15 @@
using System.Collections.Generic;
namespace Umbraco.Web.Models.TemplateQuery
{
public class QueryResultModel
{
public string QueryExpression { get; set; }
public IEnumerable<TemplateQueryResult> SampleResults { get; set; }
public int ResultCount { get; set; }
public double ExecutionTime { get; set; }
public int Take { get; set; }
}
}

View File

@@ -0,0 +1,9 @@
namespace Umbraco.Web.Models.TemplateQuery
{
public class SortExpression
{
public PropertyModel Property { get; set; }
public string Direction { get; set; }
}
}

View File

@@ -0,0 +1,8 @@
namespace Umbraco.Web.Models.TemplateQuery
{
public class SourceModel
{
public int Id { get; set; }
public string Name { get; set; }
}
}

View File

@@ -0,0 +1,9 @@
namespace Umbraco.Web.Models.TemplateQuery
{
public class TemplateQueryResult
{
public string Icon { get; set; }
public string Name { get; set; }
}
}