Repository navigation
Expand file tree
/
Copy pathuQuery-DataTypes.cs
More file actions
84 lines (76 loc) · 2.22 KB
/
Copy pathuQuery-DataTypes.cs
File metadata and controls
84 lines (76 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using System;
using System.Collections.Generic;
using System.Linq;
using umbraco.BusinessLogic;
using umbraco.cms.businesslogic.datatype;
namespace uComponents.Core
{
/// <summary>
/// Static helper methods, previously this class was UmbracoHelper
/// </summary>
public static partial class uQuery
{
/// <summary>
/// Gets all datatypes sorted by a specified property name
/// </summary>
/// <returns>
/// A sorted list of datatypes. Null if property name is wrong.
/// </returns>
public static IEnumerable<KeyValuePair<int, string>> GetAllDataTypes()
{
return GetAllDataTypes(true);
}
/// <summary>
/// Gets all datatypes sorted by a specified property name
/// </summary>
/// <param name="sortByName">if set to <c>true</c> [sort by name].</param>
/// <returns>
/// A sorted list of datatypes. Null if property name is wrong.
/// </returns>
public static IEnumerable<KeyValuePair<int, string>> GetAllDataTypes(bool sortByName)
{
var datatypes = new Dictionary<int, string>();
using (var reader = uQuery.SqlHelper.ExecuteReader("SELECT d.nodeId, n.text FROM cmsDataType d, umbracoNode n WHERE d.nodeId = n.id"))
{
// Go through the values from the database and store them in the array.
while (reader.Read())
{
if (!reader.GetInt("nodeId").Equals(new Guid()) && !string.IsNullOrEmpty(reader.GetString("text")))
{
datatypes.Add(reader.GetInt("nodeId"), reader.GetString("text"));
}
}
}
if (sortByName)
{
return datatypes.OrderBy(x => x.Value);
}
return datatypes.OrderBy(x => x.Key);
}
/// <summary>
/// Gets the data type GUID.
/// </summary>
/// <param name="datatypeNodeId">The datatype node id.</param>
/// <returns></returns>
public static Guid GetBaseDataTypeGuid(int datatypeNodeId)
{
var dataTypes = DataTypeDefinition.GetAll();
foreach (var dataTypeDefinition in dataTypes)
{
try
{
var dataType = dataTypeDefinition.DataType;
if (dataType != null && dataType.DataTypeDefinitionId == datatypeNodeId)
{
return dataTypeDefinition.DataType.Id;
}
}
catch (Exception ex)
{
Log.Add(LogTypes.Error, dataTypeDefinition.Id, ex.Message);
}
}
return new Guid();
}
}
}