public static void UpdateSeoMetaForEntity <T>(this ISeoMetaService seoMetaService, T entity, SeoMetaModel seoMetaModel) where T : FoundationEntity { var seoMeta = seoMetaService.FirstOrDefault( x => x.EntityId == entity.Id && x.EntityName == typeof(T).Name); if (seoMeta != null) { seoMeta.PageTitle = seoMetaModel.PageTitle; seoMeta.MetaKeywords = seoMetaModel.MetaKeywords; seoMeta.MetaDescription = seoMetaModel.MetaDescription; if (!seoMetaModel.Slug.IsNullEmptyOrWhiteSpace()) { //check if slug is safe to use, modify if required var slug = seoMetaModel.Slug; SeoMeta savedSeoMeta = null; var index = 1; while ((savedSeoMeta = seoMetaService.FirstOrDefault(x => x.EntityName == typeof(T).Name && x.Slug == slug && x.Id != seoMeta.Id)) != null) { slug = savedSeoMeta.Slug + (index++); } seoMeta.Slug = slug; } seoMetaService.Update(seoMeta); } }
public void OnInserted(T entity) { if (!(entity is ISeoEntity)) { return; } var name = ((ISeoEntity)entity).Name; var seoMeta = new SeoMeta() { EntityId = entity.Id, EntityName = typeof(T).Name, LanguageCultureCode = ApplicationEngine.CurrentLanguageCultureCode, Slug = CommonHelper.GenerateSlug(name), PageTitle = name }; _seoMetaService.Insert(seoMeta); //is there a property to for seometa var property = typeof(T).GetProperties().FirstOrDefault(x => x.PropertyType == typeof(SeoMeta) && x.CanWrite); if (property != null) { property.SetValue(entity, seoMeta); } }
public static string GetUrl(SeoMeta seoMeta) { switch (seoMeta.EntityName) { case nameof(Product): return(ApplicationEngine.RouteUrl(RouteNames.SingleProduct, new { seName = seoMeta.Slug, id = seoMeta.EntityId })); case nameof(Category): return(ApplicationEngine.RouteUrl(RouteNames.ProductsPage, new { seName = seoMeta.Slug, id = seoMeta.EntityId })); case nameof(ContentPage): return(ApplicationEngine.RouteUrl(RouteNames.SinglePage, new { seName = seoMeta.Slug, id = seoMeta.EntityId })); } return(null); }
public static void SetSeoData(string title, string description = null, string keywords = null) { var seoMeta = ApplicationEngine.CurrentHttpContext.GetRequestSeoMeta(); if (seoMeta == null) { seoMeta = new SeoMeta(); ApplicationEngine.CurrentHttpContext.SetRequestSeoMeta(seoMeta); } if (seoMeta.PageTitle.IsNullEmptyOrWhiteSpace()) { seoMeta.PageTitle = HtmlUtility.StripHtml(title); } if (seoMeta.MetaKeywords.IsNullEmptyOrWhiteSpace()) { seoMeta.MetaKeywords = HtmlUtility.StripHtml(keywords); } if (seoMeta.MetaDescription.IsNullEmptyOrWhiteSpace()) { seoMeta.MetaDescription = HtmlUtility.StripHtml(description); } }
public static void SetRequestSeoMeta(this HttpContext httpContext, SeoMeta seoMeta) { httpContext.Items[RequestSeoMetaKey] = seoMeta; }