-
-
Save pynej/576b138748daef2925b6526b7d56bca8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Newtonsoft.Json.Linq; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Web; | |
using Umbraco.Core; | |
using Umbraco.Core.Services; | |
using Umbraco.Web; | |
namespace Project.Models | |
{ | |
public class School | |
{ | |
private JToken _self; | |
public School(JToken self) | |
{ | |
_self = self; | |
} | |
public int Id | |
{ | |
get | |
{ | |
return (int)_self["school"]; | |
} | |
} | |
private string _Name; | |
public string Name | |
{ | |
get | |
{ | |
if (_Name == null) | |
_Name = UmbracoContext.Current.ContentCache.GetById(Id).Name; | |
return _Name; | |
} | |
} | |
public int Level | |
{ | |
get | |
{ | |
return (int)_self["level"]; | |
} | |
} | |
public override string ToString() | |
{ | |
return Name + " " + Level; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Newtonsoft.Json.Linq; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Web; | |
using System.Collections; | |
using Mage_Wars_Spellbook_Builder.Helpers; | |
namespace Project.Models | |
{ | |
public class Schools : IEnumerable<School> | |
{ | |
private JArray _self; | |
public Schools(JArray self) | |
{ | |
_self = self; | |
} | |
public new static Schools Parse(string json) | |
{ | |
return new Schools(JArray.Parse(json)); | |
} | |
public IEnumerator<School> GetEnumerator() | |
{ | |
return (_self == null ? new School[] { } : _self.Children().Select(s => s.As<School>())).GetEnumerator(); | |
} | |
IEnumerator IEnumerable.GetEnumerator() | |
{ | |
return (_self == null ? new School[] { } : _self.Children().Select(s => s.As<School>())).GetEnumerator(); | |
} | |
public bool HasSchool(string school) | |
{ | |
return this.Where(s => s.Name == school).Count() > 0; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Web; | |
using Umbraco.Core.Models.PublishedContent; | |
using Umbraco.Core.PropertyEditors; | |
namespace Project.Models.PropertyConverters | |
{ | |
[PropertyValueType(typeof(Schools))] | |
[PropertyValueCache(PropertyCacheValue.All, PropertyCacheLevel.Content)] | |
public class SchoolsPropertyConverter : PropertyValueConverterBase | |
{ | |
private readonly string PropertyEditorAlias = "NestedDataType"; | |
private readonly int[] DataTypeId = { 1096 }; | |
public override bool IsConverter(PublishedPropertyType propertyType) | |
{ | |
return propertyType.PropertyEditorAlias.Equals(PropertyEditorAlias) && DataTypeId.Contains(propertyType.DataTypeId); | |
} | |
public override object ConvertSourceToObject(PublishedPropertyType propertyType, object source, bool preview) | |
{ | |
if (source == null) | |
{ | |
return null; | |
} | |
try | |
{ | |
return Schools.Parse((string)source); | |
} | |
catch | |
{ | |
return null; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment