public Task <ContentType[]> GetContentTypes(ContentTypeQuery query) { var q = _liteRepository.Query <ContentType>(); if (!string.IsNullOrEmpty(query.AppId)) { if (query.IncludeGlobalContentTypes) { q = q.Where(ct => ct.AppId == query.AppId || ct.AppId == null); } else { q = q.Where(ct => ct.AppId == query.AppId); } } if (!string.IsNullOrEmpty(query.Id)) { q = q.Where(ct => ct.Id == query.Id); } if (!string.IsNullOrEmpty(query.Name)) { q = q.Where(ct => ct.Name == query.Name); } var result = q.ToArray().OrderByDescending(ct => ct.AppId).OrderBy(ct => ct.Name).ToArray(); return(Task.FromResult(result)); }
public async Task <ContentType[]> GetContentTypes(ContentTypeQuery query) { var globalContentTypes = (query.AppId == null || query.IncludeGlobalContentTypes) ? await _queries.GetAllAsync(Constants.GlobalProjectId) : new List <ContentType>(); var contentTypesForAppId = !String.IsNullOrEmpty(query.AppId) ? await _queries.GetAllAsync(query.AppId) : new List <ContentType>(); var contentTypes = globalContentTypes.Union(contentTypesForAppId); if (!string.IsNullOrEmpty(query.Id)) { contentTypes = contentTypes.Where(ct => ct.Id == query.Id); } if (!string.IsNullOrEmpty(query.Name)) { contentTypes = contentTypes.Where(ct => ct.Name == query.Name); } return(contentTypes.OrderByDescending(ct => ct.AppId).ThenBy(ct => ct.Name).ToArray()); }
public async Task StartAsync(CancellationToken cancellationToken) { // Ensure that the global Translations content type exists using (var scope = _serviceProvider.CreateScope()) { var logger = scope.ServiceProvider.GetRequiredService <ILogger <TranslationsInitializer> >(); logger.LogInformation($"Initializing AppText.Translations"); var contentDefinitionStore = scope.ServiceProvider.GetRequiredService <IContentDefinitionStore>(); var translationContentTypeQuery = new ContentTypeQuery { AppId = null, Name = "Translation" }; var translationContentType = (await contentDefinitionStore.GetContentTypes(translationContentTypeQuery)).FirstOrDefault(); if (translationContentType == null) { logger.LogInformation($"Global Translation content type not found, creating..."); await contentDefinitionStore.AddContentType(new ContentType { AppId = null, // global Name = Constants.TranslationContentType, Description = "Built-in content type for translations", ContentFields = new Field[] { new Field { Name = Constants.TranslationTextFieldName, Description = "Text", FieldType = new ShortText(), IsRequired = true } }, Version = 0 }); } else { logger.LogInformation($"Global Translation content type already registered. Skipping creation..."); } } }
public static IQueryExpression FilterByContentType <T>(this IQueryExpression expression, bool includeInherit = false) where T : ContentData { var contentTypeQuery = new ContentTypeQuery <T>(includeInherit); return(expression.And(contentTypeQuery)); }