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 OnUpdated(T entity) { if (!(entity is ISeoEntity)) { return; } var name = ((ISeoEntity)entity).Name; var seoMeta = _seoMetaService.GetForEntity <T>(entity.Id); if (seoMeta != null) { if (seoMeta.PageTitle.IsNullEmptyOrWhiteSpace()) { seoMeta.PageTitle = name; _seoMetaService.Update(seoMeta); } } }