// --------------------------------------------------------------------------------------------------------------------
//
// Umbraco
//
//
// Defines the RelatedLinks type.
//
// --------------------------------------------------------------------------------------------------------------------
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Umbraco.Core.Logging;
namespace Umbraco.Web.Models
{
///
/// The related links model
///
public class RelatedLinks : IEnumerable
{
// ReSharper disable InconsistentNaming
///
/// The _property data.
///
private readonly string _propertyData;
///
/// The _related links.
///
private readonly List _relatedLinks = new List();
///
/// Initializes a new instance of the class.
///
///
/// The property data.
///
public RelatedLinks(string propertyData)
{
this._propertyData = propertyData;
if (!string.IsNullOrEmpty(propertyData))
{
var relatedLinks = JsonConvert.DeserializeObject(propertyData);
foreach (var item in relatedLinks)
{
var relatedLink = new RelatedLink(item);
if (!relatedLink.InternalLinkDeleted)
{
this._relatedLinks.Add(relatedLink);
}
else
{
LogHelper.Warn(
string.Format("Related Links value converter skipped a link as the node has been unpublished/deleted (Internal Link NodeId: {0}, Link Caption: \"{1}\")", relatedLink.Link, relatedLink.Caption));
}
}
}
}
///
/// Gets the property data.
///
public string PropertyData
{
get
{
return this._propertyData;
}
}
///
/// The any.
///
///
/// The .
///
public bool Any()
{
return Enumerable.Any(this);
}
///
/// The get enumerator.
///
///
/// The .
///
public IEnumerator GetEnumerator()
{
return this._relatedLinks.GetEnumerator();
}
///
/// The get enumerator.
///
///
/// The .
///
IEnumerator IEnumerable.GetEnumerator()
{
return this.GetEnumerator();
}
}
}