public static T As <T>(this ArchetypeFieldsetModel fieldset) { var instance = Activator.CreateInstance <T>(); var properties = typeof(T).GetProperties(BindingFlags.Instance | BindingFlags.Public) .Where(prop => !prop.IsDefined(typeof(JsonIgnoreAttribute))); foreach (var propInfo in properties) { var jsonPropAttribute = propInfo.GetCustomAttribute <JsonPropertyAttribute>(true); var propertyAlias = jsonPropAttribute != null ? jsonPropAttribute.PropertyName : propInfo.Name; var propertyType = propInfo.PropertyType; if (!fieldset.HasProperty(propertyAlias) && !fieldset.HasValue(propertyAlias)) { continue; } propInfo.SetValue(instance, fieldset.GetType().GetMethods().First(m => m.IsGenericMethod && m.Name.Equals("GetValue")) .MakeGenericMethod(propertyType) .Invoke(fieldset, new object[] { propertyAlias })); } return(instance); }
internal Reward(ArchetypeFieldsetModel archetypeFieldsetModel) { this.Heading = archetypeFieldsetModel.GetValue <string>("heading"); this.Image = new Image(archetypeFieldsetModel.GetValue <IPublishedContent>("image")); this.SubHeading = archetypeFieldsetModel.GetValue <string>("subHeading"); this.Copy = archetypeFieldsetModel.GetValue <string>("copy"); }
/// <summary> /// Renders the fieldset partial /// </summary> /// <param name="htmlHelper">The HTML helper.</param> /// <param name="fieldsetModel"></param> /// <param name="partialPath">The partial path.</param> /// <param name="viewDataDictionary">The view data dictionary.</param> /// <returns></returns> private static IHtmlString _renderPartial(HtmlHelper htmlHelper, ArchetypeFieldsetModel fieldsetModel, string partialPath, ViewDataDictionary viewDataDictionary) { var context = HttpContext.Current; if (fieldsetModel == null || context == null) { return(new HtmlString("")); } var sb = new StringBuilder(); //default var pathToPartials = "~/Views/Partials/Archetype/"; if (!string.IsNullOrEmpty(partialPath)) { pathToPartials = partialPath; } var partial = string.Format("{0}{1}.cshtml", pathToPartials, fieldsetModel.Alias); if (System.IO.File.Exists(context.Server.MapPath(partial))) { sb.AppendLine(htmlHelper.Partial(partial, fieldsetModel, viewDataDictionary).ToString()); } else { LogHelper.Info <ArchetypeModel>(string.Format("The partial for {0} could not be found. Please create a partial with that name or rename your alias.", context.Server.MapPath(partial))); } return(new HtmlString(sb.ToString())); }
internal PromotionTile(ArchetypeFieldsetModel archetypeFieldsetModel) { this.Image = new Image(archetypeFieldsetModel.GetValue <IPublishedContent>("image")); this.OverlayImage = new Image(archetypeFieldsetModel.GetValue <IPublishedContent>("overlayImage")); this.AltText = archetypeFieldsetModel.GetValue <string>("altText"); this.Link = archetypeFieldsetModel.GetValue <MultiUrls>("link").Single().Url; }
/// <summary> /// Renders the fieldset partial /// </summary> /// <param name="htmlHelper">The HTML helper.</param> /// <param name="fieldsetModel"></param> /// <param name="partialPath">The partial path.</param> /// <param name="viewDataDictionary">The view data dictionary.</param> /// <returns></returns> private static IHtmlString RenderPartial(HtmlHelper htmlHelper, ArchetypeFieldsetModel fieldsetModel, string partialPath, ViewDataDictionary viewDataDictionary) { var context = HttpContext.Current; if (fieldsetModel == null || context == null) { return new HtmlString(""); } var sb = new StringBuilder(); var pathToPartials = "~/Views/Partials/Archetype/"; if (!string.IsNullOrEmpty(partialPath)) { pathToPartials = partialPath; } var partial = pathToPartials + fieldsetModel.Alias + ".cshtml"; if (System.IO.File.Exists(context.Server.MapPath(partial))) { sb.AppendLine(htmlHelper.Partial(partial, fieldsetModel, viewDataDictionary).ToString()); } else { LogHelper.Info<ArchetypeModel>(string.Format("The partial for {0} could not be found. Please create a partial with that name or rename your alias.", context.Server.MapPath(partial))); } return new HtmlString(sb.ToString()); }
public static IPublishedContent ToPublishedContent(this ArchetypeFieldsetModel fieldset, ArchetypeModel archetype) { var contentSet = archetype.ToPublishedContentSet(); var first = contentSet .Cast <ArchetypePublishedContent>() .FirstOrDefault(x => x.ArchetypeFieldset == fieldset); return(first ?? new ArchetypePublishedContent(fieldset)); }
public void Null_ArchetypeFieldsetModel_Throws_Exception() { TestDelegate code = () => { ArchetypeFieldsetModel fieldset = null; fieldset.ToPublishedContent(); }; Assert.Throws <ArgumentNullException>(code); }
public ArchetypePublishedContent(ArchetypeFieldsetModel fieldset) { if (fieldset == null) throw new ArgumentNullException("fieldset"); _fieldset = fieldset; _properties = fieldset.Properties .ToDictionary( x => x.Alias, x => new ArchetypePublishedProperty(x) as IPublishedProperty, StringComparer.InvariantCultureIgnoreCase); }
/// <summary> /// Konstruktor /// </summary> /// <param name="model"></param> public AccordionViewModel(ArchetypeFieldsetModel model) { _model = model; }
/// <summary> /// Renders the archetype partial. /// </summary> /// <param name="htmlHelper">The HTML helper.</param> /// <param name="fieldsetModel">The fieldset model.</param> /// <param name="partialView">The partial view.</param> /// <param name="viewDataDictionary">The view data dictionary.</param> /// <returns></returns> public static IHtmlString RenderArchetypePartial(this HtmlHelper htmlHelper, ArchetypeFieldsetModel fieldsetModel, string partialView, ViewDataDictionary viewDataDictionary) { return _renderPartial(htmlHelper, fieldsetModel, partialView, viewDataDictionary); }
public static IPublishedContent ToPublishedContent(this ArchetypeFieldsetModel fieldset) { return(new ArchetypePublishedContent(fieldset)); }
private static void setValueArchetypeFieldsetProperty(ArchetypeFieldsetModel ArchetypeFieldset, string PropertyAlias, object value) { var property = ArchetypeFieldset.Properties.FirstOrDefault(x => x.Alias == PropertyAlias); property.Value = value; }
public RegionContactBox(ArchetypeFieldsetModel model) { _model = model; }
/// <summary> /// Renders the archetype partial. /// </summary> /// <param name="htmlHelper">The HTML helper.</param> /// <param name="fieldsetModel">The fieldset model.</param> /// <param name="partialView">The partial view.</param> /// <param name="viewDataDictionary">The view data dictionary.</param> /// <returns></returns> public static IHtmlString RenderArchetypePartial(this HtmlHelper htmlHelper, ArchetypeFieldsetModel fieldsetModel, string partialView, ViewDataDictionary viewDataDictionary) { return(_renderPartial(htmlHelper, fieldsetModel, partialView, viewDataDictionary)); }
/// <summary> /// Renders the archetype partial. /// </summary> /// <param name="htmlHelper">The HTML helper.</param> /// <param name="fieldsetModel">The fieldset model.</param> /// <param name="partialView">The partial view.</param> /// <returns></returns> public static IHtmlString RenderArchetypePartial(this HtmlHelper htmlHelper, ArchetypeFieldsetModel fieldsetModel, string partialView) { return(_renderPartial(htmlHelper, fieldsetModel, partialView, null)); }
internal QuestionAndAnswer(ArchetypeFieldsetModel archetypeFieldsetModel) { this.Question = archetypeFieldsetModel.GetValue <string>("question"); this.Answer = archetypeFieldsetModel.GetValue <string>("answer"); }
/// <summary> /// Renders the archetype partial. /// </summary> /// <param name="htmlHelper">The HTML helper.</param> /// <param name="fieldsetModel">The fieldset model.</param> /// <param name="partialView">The partial view.</param> /// <returns></returns> public static IHtmlString RenderArchetypePartial(this HtmlHelper htmlHelper, ArchetypeFieldsetModel fieldsetModel, string partialView) { return _renderPartial(htmlHelper, fieldsetModel, partialView, null); }
/// <summary> /// Renders a single archtype partial from a fieldset /// </summary> /// <param name="htmlHelper">The HTML helper.</param> /// <param name="fieldsetModel">The fieldset model.</param> /// <returns></returns> public static IHtmlString RenderArchetypePartial(this HtmlHelper htmlHelper, ArchetypeFieldsetModel fieldsetModel) { return RenderPartial(htmlHelper, fieldsetModel, null, null); }