Пример #1
0
        protected override async Task ValidateCustom(ContentType objectToValidate)
        {
            // Verify app reference
            if (!String.IsNullOrEmpty(objectToValidate.AppId))
            {
                var app = await _applicationStore.GetApp(objectToValidate.AppId);

                if (app == null)
                {
                    AddError(new ValidationError {
                        Name = "AppId", ErrorMessage = "AppNotFound", Parameters = new[] { objectToValidate.AppId }
                    });
                }
            }
            else
            {
                AddError(new ValidationError {
                    Name = "AppId", ErrorMessage = "AppIdEmpty"
                });
            }

            // Duplicate content type name
            if (this.Errors.Count() == 0 && objectToValidate.AppId != null)
            {
                var contentTypesWithSameName = await _contentDefinitionStore.GetContentTypes(new ContentTypeQuery { AppId = objectToValidate.AppId, Name = objectToValidate.Name });

                if (contentTypesWithSameName.Any(ct => ct.Id != objectToValidate.Id))
                {
                    AddError(new ValidationError {
                        Name = "Name", ErrorMessage = "DuplicateContentTypeName", Parameters = new[] { objectToValidate.Name }
                    });
                }
            }
        }
Пример #2
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));
        }
Пример #3
0
        protected override async Task ValidateCustom(ContentCollection objectToValidate)
        {
            // Check content type
            var contentTypeId = objectToValidate.ContentType.Id;
            var appId         = objectToValidate.ContentType.AppId;
            var contentType   = (await _contentDefinitionStore.GetContentTypes(new ContentTypeQuery {
                Id = contentTypeId, AppId = appId, IncludeGlobalContentTypes = true
            })).FirstOrDefault();

            if (contentType == null)
            {
                AddError("ContentType.Id", "UnknownContentType", contentTypeId);
            }
            else
            {
                // Sync content type with collection when valid
                objectToValidate.ContentType       = contentType;
                objectToValidate.ContentType.AppId = appId; // Keep appId because that one can be empty in case of a global content type.

                // Check uniqueness of name
                var otherCollection = (await _contentStore.GetContentCollections(new ContentCollectionQuery {
                    Name = objectToValidate.Name, AppId = appId
                })).FirstOrDefault();
                if (otherCollection != null)
                {
                    if (objectToValidate.Id == null || objectToValidate.Id != otherCollection.Id)
                    {
                        AddError("Name", "DuplicateContentCollectionName", objectToValidate.Name);
                    }
                }

                // Check if ListDisplayField is actually in the content type
                if (!string.IsNullOrEmpty(objectToValidate.ListDisplayField) && !contentType.ContentFields.Any(cf => cf.Name == objectToValidate.ListDisplayField))
                {
                    AddError("ListDisplayField", "ListDisplayFieldIsNotInContentFields", objectToValidate.ListDisplayField);
                }
            }
        }
Пример #4
0
 public Task <ContentType[]> Handle(ContentTypeQuery query)
 {
     return(_store.GetContentTypes(query));
 }