/// <summary> /// Builds a page model object from the given page. /// </summary> /// <param name="db">The data context</param> /// <param name="page">The page</param> /// <returns>The model</returns> private static PageModel BuildModel(DataContext db, Page page) { var m = new PageModel() ; m.Page = page ; // Get Properties foreach (var pt in page.Template.Properties) { var val = page.Properties.Where(p => p.Name == pt).SingleOrDefault() ; if (val != null) ((IDictionary<string, object>)m.Properties).Add(pt, val.Value) ; else ((IDictionary<string, object>)m.Properties).Add(pt, "") ; } // Get Media var media = db.Media.Where(med => page.Attachments.Contains(med.Id)).ToList() ; foreach (var attachment in page.Attachments) { var val = media.Where(med => med.Id == attachment).SingleOrDefault() ; if (val != null) m.Attachments.Add(val) ; } // Get Regions foreach (var rt in page.Template.RegionTemplates) { if (App.Instance.ExtensionManager.HasType(rt.Type)) { object val = null ; var reg = page.Regions.Where(r => r.RegionTemplateId == rt.Id).SingleOrDefault() ; if (reg != null) { if (reg.RegionTemplate == null) reg.RegionTemplate = rt ; val = reg.Body ; } else val = App.Instance.ExtensionManager.CreateInstance(rt.Type) ; // Initialize region val = ((IExtension)val).GetContent(m) ; // Check for post region if (val is Extend.Regions.PostRegion) val = ((Extend.Regions.PostRegion)val).GetMatchingPosts(); ((IDictionary<string, object>)m.Regions).Add(rt.InternalId, val) ; } else ((IDictionary<string, object>)m.Regions).Add(rt.InternalId, null) ; } // Get Extensions foreach (var ext in page.Extensions) { object val = null ; if (App.Instance.ExtensionManager.HasType(ext.Type)) { val = ext.Body ; } } return m ; }
/// <summary> /// Builds a page model object from the given page. /// </summary> /// <param name="db">The data context</param> /// <param name="page">The page</param> /// <returns>The model</returns> private static PageModel BuildModel(DataContext db, Page page) { var m = new PageModel() ; m.Page = page ; // Get Properties foreach (var pt in page.Template.Properties) { var val = page.Properties.Where(p => p.Name == pt).SingleOrDefault() ; if (val != null) ((IDictionary<string, object>)m.Properties).Add(pt, val.Value) ; else ((IDictionary<string, object>)m.Properties).Add(pt, "") ; } // Get Media var media = db.Media.Where(med => page.Attachments.Contains(med.Id)).ToList() ; foreach (var attachment in page.Attachments) { var val = media.Where(med => med.Id == attachment).SingleOrDefault() ; if (val != null) m.Attachments.Add(val) ; } // Get Regions foreach (var rt in page.Template.RegionTemplates) { if (ExtensionManager.ExtensionTypes.ContainsKey(rt.Type)) { object val = null ; var reg = page.Regions.Where(r => r.RegionTemplateId == rt.Id).SingleOrDefault() ; if (reg != null) { if (reg.RegionTemplate == null) reg.RegionTemplate = rt ; val = reg.Body ; } else val = Activator.CreateInstance(ExtensionManager.ExtensionTypes[rt.Type]) ; // Initialize region var method = ExtensionManager.ExtensionTypes[rt.Type].GetMethod("GetContent") ; if (method != null) val = method.Invoke(val, new object[] { m }) ; ((IDictionary<string, object>)m.Regions).Add(rt.InternalId, val) ; } else ((IDictionary<string, object>)m.Regions).Add(rt.InternalId, null) ; } // Get Extensions foreach (var ext in page.Extensions) { object val = null ; if (ExtensionManager.ExtensionTypes.ContainsKey(ext.Type)) { val = ext.Body ; } } return m ; }
/// <summary> /// Builds a page model object from the given page. /// </summary> /// <param name="db">The data context</param> /// <param name="page">The page</param> /// <returns>The model</returns> private static PageModel BuildModel(DataContext db, Page page) { var m = new PageModel(); m.Page = page; // Get Properties foreach (var pt in page.Template.Properties) { var val = page.Properties.Where(p => p.Name == pt).SingleOrDefault(); if (val != null) { ((IDictionary <string, object>)m.Properties).Add(pt, val.Value); } else { ((IDictionary <string, object>)m.Properties).Add(pt, ""); } } // Get Media var media = db.Media.Where(med => page.Attachments.Contains(med.Id)).ToList(); foreach (var attachment in page.Attachments) { var val = media.Where(med => med.Id == attachment).SingleOrDefault(); if (val != null) { m.Attachments.Add(val); } } // Get Regions foreach (var rt in page.Template.RegionTemplates) { if (ExtensionManager.ExtensionTypes.ContainsKey(rt.Type)) { object val = null; var reg = page.Regions.Where(r => r.RegionTemplateId == rt.Id).SingleOrDefault(); if (reg != null) { if (reg.RegionTemplate == null) { reg.RegionTemplate = rt; } val = reg.Body; } else { val = Activator.CreateInstance(ExtensionManager.ExtensionTypes[rt.Type]); } // Initialize region var method = ExtensionManager.ExtensionTypes[rt.Type].GetMethod("GetContent"); if (method != null) { val = method.Invoke(val, new object[] { m }); } ((IDictionary <string, object>)m.Regions).Add(rt.InternalId, val); } else { ((IDictionary <string, object>)m.Regions).Add(rt.InternalId, null); } } // Get Extensions foreach (var ext in page.Extensions) { object val = null; if (ExtensionManager.ExtensionTypes.ContainsKey(ext.Type)) { val = ext.Body; } } return(m); }