Пример #1
0
        public async Task <IActionResult> Get(string appId, string language, string collection = null)
        {
            // Get all collections with the Translation content type and then return all content as key-value pairs, ordered by key.
            var translationContentType = (await _contentDefinitionStore.GetContentTypes(new ContentTypeQuery {
                AppId = null, Name = Constants.TranslationContentType, IncludeGlobalContentTypes = true
            })).FirstOrDefault();

            if (translationContentType == null)
            {
                return(NotFound($"The {Constants.TranslationContentType} content type could not be found"));
            }

            var contentCollectionQuery = new ContentCollectionQuery
            {
                AppId = appId
            };

            if (!string.IsNullOrEmpty(collection))
            {
                contentCollectionQuery.Name = collection;
            }
            var collections = (await _contentStore.GetContentCollections(contentCollectionQuery)).Where(c => c.ContentType.Id == translationContentType.Id);

            var result = new TranslationResult
            {
                Language   = language,
                Collection = collection
            };

            foreach (var contentCollection in collections)
            {
                var contentItems = await _contentStore.GetContentItems(new ContentItemQuery { AppId = appId, CollectionId = contentCollection.Id });

                foreach (var contentItem in contentItems)
                {
                    var entry = new TranslationResultEntry
                    {
                        Key        = contentItem.ContentKey,
                        Collection = contentCollection.Name
                    };
                    //entry.Value = entry.Key; // set translation to key as default
                    if (contentItem.Content.ContainsKey(Constants.TranslationTextFieldName))
                    {
                        var contentItemFieldValue = JObject.FromObject(contentItem.Content[Constants.TranslationTextFieldName]);
                        if (contentItemFieldValue != null)
                        {
                            var jToken = contentItemFieldValue.GetValue(language);
                            if (jToken != null)
                            {
                                entry.Value = jToken.ToString();
                            }
                        }
                    }
                    result.Entries.Add(entry);
                }
            }
            return(Ok(result));
        }
Пример #2
0
        public Task <ContentCollection[]> GetContentCollections(ContentCollectionQuery query)
        {
            var q = _liteRepository.Query <ContentCollection>();

            if (!string.IsNullOrEmpty(query.AppId))
            {
                q = q.Where(cc => cc.ContentType.AppId == query.AppId);
            }
            if (!string.IsNullOrEmpty(query.Id))
            {
                q = q.Where(cc => cc.Id == query.Id);
            }
            if (!string.IsNullOrEmpty(query.Name))
            {
                q = q.Where(cc => cc.Name == query.Name);
            }
            return(Task.FromResult(q.OrderBy(cc => cc.Name).ToArray()));
        }
Пример #3
0
        public async Task <ContentCollection[]> GetContentCollections(ContentCollectionQuery query)
        {
            if (String.IsNullOrEmpty(query.AppId))
            {
                throw new ArgumentException("NoDbStorage always requires the AppId property");
            }
            var contentCollections = await _contentColllectionQueries.GetAllAsync(query.AppId);

            if (!string.IsNullOrEmpty(query.Id))
            {
                contentCollections = contentCollections.Where(cc => cc.Id == query.Id);
            }
            if (!string.IsNullOrEmpty(query.Name))
            {
                contentCollections = contentCollections.Where(cc => cc.Name == query.Name);
            }
            return(contentCollections.OrderBy(cc => cc.Name).ToArray());
        }