public static Func <T1, IHtmlContent> Helper <T1>( this RazorPageBase page, Func <T1, Func <object, IHtmlContent> > helper ) => p1 => helper(p1)(null);
public static Func <T1, T2, T3, IHtmlContent> Helper <T1, T2, T3>( this RazorPageBase page, Func <T1, T2, T3, Func <object, IHtmlContent> > helper ) => (p1, p2, p3) => helper(p1, p2, p3)(null);
public static bool IsAjaxRequest(this RazorPageBase page) => page.ViewContext.HttpContext.Request.IsAjax();
public static T PuckEditorSettings <T>(this RazorPageBase page, string propertyName = "", bool inherit = true, Type modelTypeOverride = null, bool attributeOnly = false) { int cacheMinutes = 30; if (page.ViewContext.ViewData.ModelMetadata != null) { var settingsAttribute = page.ViewContext.ViewData.ModelMetadata.GetPropertyAttribute <T>(); if (settingsAttribute != null) { return((T)settingsAttribute); } } if (attributeOnly) { return(default(T)); } if (string.IsNullOrEmpty(propertyName)) { propertyName = page.ViewContext.ViewData.TemplateInfo.HtmlFieldPrefix; } using (var scope = PuckCache.ServiceProvider.CreateScope()) { var repo = scope.ServiceProvider.GetService <I_Puck_Repository>(); var cache = scope.ServiceProvider.GetService <IMemoryCache>(); var modelType = modelTypeOverride == null? page.ViewBag.Level0Type as Type :modelTypeOverride; if (modelType == null) { return(default(T)); } var settingsType = typeof(T); //var propertyName =ExpressionMetadataProvider.FromStringExpression("", page.ViewData,).PropertyName; var type = modelType; var cachePrefix = "editor_settings_"; while (type != typeof(object)) { var key = string.Concat(settingsType.FullName, ":", type.Name, ":", propertyName); var cacheKey = cachePrefix + key; var meta = cache.Get <PuckMeta>(cacheKey); if (meta == null) { if (!cache.Get <bool?>("null_" + cacheKey).HasValue) { meta = repo.GetPuckMeta().Where(x => x.Name == DBNames.EditorSettings && x.Key.Equals(key)).FirstOrDefault(); if (meta != null) { cache.Set(cacheKey, meta, TimeSpan.FromMinutes(cacheMinutes)); } else { bool?nullValue = true; cache.Set("null_" + cacheKey, nullValue, TimeSpan.FromMinutes(cacheMinutes)); } } if (meta == null) { key = string.Concat(settingsType.FullName, ":", type.Name, ":"); cacheKey = cachePrefix + key; meta = cache.Get <PuckMeta>(cacheKey); if (meta == null) { if (!cache.Get <bool?>("null_" + cacheKey).HasValue) { meta = repo.GetPuckMeta().Where(x => x.Name == DBNames.EditorSettings && x.Key.Equals(key)).FirstOrDefault(); if (meta != null) { cache.Set(cacheKey, meta, TimeSpan.FromMinutes(cacheMinutes)); } else { bool?nullValue = true; cache.Set("null_" + cacheKey, nullValue, TimeSpan.FromMinutes(cacheMinutes)); } } } } } if (meta != null) { var data = JsonConvert.DeserializeObject(meta.Value, settingsType); return(data == null ? default(T) : (T)data); } if (inherit) { type = type.BaseType; } else { type = typeof(object); } } return(default(T)); } }
/// <summary> /// Instantiates a new instance of <see cref="RazorPageAdapter"/>. /// </summary> /// <param name="page">The <see cref="RazorPageBase"/>.</param> /// <param name="modelType">The model type.</param> public RazorPageAdapter(RazorPageBase page, Type modelType) { _page = page ?? throw new ArgumentNullException(nameof(page)); _modelType = modelType ?? throw new ArgumentNullException(nameof(modelType)); }
public static HtmlString ActionJs(this RazorPageBase page) { return(ActionJs(page.ViewContext)); }