Exemple #1
0
        public async Task <IEnumerable <IContent> > GetAncestorsAsync(IContent content)
        {
            var result = new List <IContent>();

            var position    = content;
            var contentType = ContentTypeProvider.Get(content.ContentTypeId);

            while (true)
            {
                var document = (await DocumentFinder.Find(contentType.Container).WhereEquals <IContent, string>(x => x.Id, ((IHierarchical)position).ParentId).WhereExists <IHierarchical, string>(x => x.ParentId).GetResultAsync().ConfigureAwait(false)).FirstOrDefault();

                if (document == null)
                {
                    break;
                }

                contentType = ContentTypeProvider.Get((string)document.GlobalFacet.Interfaces["IContent"].Properties["ContentTypeId"]);
                position    = ContentDeserializer.Deserialize(document, contentType, null);

                result.Add(position);

                if (((IHierarchical)position).ParentId == null)
                {
                    break;
                }
            }

            return(result);
        }
Exemple #2
0
        public async Task <User> FindByNameAsync(string normalizedUserName, CancellationToken cancellationToken)
        {
            var document = (await DocumentFinder.Find(Container).WhereEquals <User, string>(u => u.NormalizedUsername, normalizedUserName).GetResultAsync()).FirstOrDefault();

            if (document == null)
            {
                return(null);
            }

            var content = ContentDeserializer.Deserialize(document, ContentType, null) as User;

            return(content);
        }
Exemple #3
0
        public IContent RouteContentSegment(string parentId, string segment, string language)
        {
            var document = DocumentFinder.Find(ContainerConstants.Content).WhereEquals <IHierarchical, string>(x => x.ParentId, parentId).WhereEquals <IRoutable, string>(x => x.UrlSegment, segment).GetResultAsync().Result.FirstOrDefault();

            if (document == null)
            {
                return(null);
            }

            var contentType = ContentTypeRepository.Get(document.GlobalFacet.Interfaces["IContent"].Properties["ContentTypeId"] as string);

            return(ContentDeserializer.Deserialize(document, contentType, language));
        }
Exemple #4
0
        public IEnumerable <T> GetChildren <T>(string id, string language) where T : class
        {
            var contentTypes = ContentTypeProvider.GetAll().Where(t => typeof(T).IsAssignableFrom(t.Type));

            var documents = DocumentFinder.Find(ContainerConstants.Content).WhereEquals <IHierarchical, string>(x => x.ParentId, id).WhereIn <IContent, string>(x => x.ContentTypeId, contentTypes.Select(t => t.Id)).GetResultAsync().Result.ToList();

            var result = new List <T>();

            foreach (var document in documents)
            {
                var contentTypeId = document.GlobalFacet.Interfaces["IContent"].Properties["ContentTypeId"] as string;

                result.Add((T)ContentDeserializer.Deserialize(document, ContentTypeProvider.Get(contentTypeId), language));
            }

            return(result.AsReadOnly());
        }
        public async Task <IEnumerable <Item> > GetAll(string type)
        {
            var result = new List <Item>();

            var contentType = ContentTypeProvider.Get(type);

            foreach (var document in await DocumentFinder.Find(contentType.Container).GetResultAsync().ConfigureAwait(false))
            {
                if (document.GlobalFacet.Interfaces[nameof(IContent)].Properties[nameof(IContent.ContentTypeId)] as string != type)
                {
                    continue;
                }
                var content = ContentDeserializer.Deserialize(document, contentType, null);
                result.Add(new Item((content as INameable)?.Name ?? content.Id, null, content.Id, (content as IImageable)?.Image));
            }

            return(result.AsReadOnly());
        }
Exemple #6
0
        public IEnumerable <object> GetContentList(string contentTypeId)
        {
            var contentType = ContentTypeProvider.Get(contentTypeId);

            var documents = DocumentFinder.Find(contentType.Container).WhereEquals <IContent, string>(x => x.ContentTypeId, contentType.Id).GetResultAsync().Result.ToList();

            var result = new List <object>();

            foreach (var document in documents)
            {
                result.Add(ContentDeserializer.Deserialize(document, contentType, DocumentLanguageConstants.Global));
            }

            var sortByPropertyName = typeof(INameable).IsAssignableFrom(contentType.Type) ? "Name" : "Id";
            var sortByProperty     = PropertyDefinitionProvider.GetFor(contentType.Id).FirstOrDefault(p => p.Name == sortByPropertyName);

            if (sortByProperty != null)
            {
                result = result.OrderBy(i => sortByProperty.Getter(i)).ToList();
            }

            return(result.AsReadOnly());
        }
        public IEnumerable <Option> GetAll()
        {
            var contentTypes = ContentTypeProvider.GetAll().Where(t => typeof(IHierarchical).IsAssignableFrom(t.Type));

            var result = new List <Option>();

            foreach (var contentType in contentTypes)
            {
                var documents = DocumentFinder.Find(contentType.Container).WhereEquals <IContent, string>(x => x.ContentTypeId, contentType.Id).GetResultAsync().Result.ToList();

                foreach (var document in documents)
                {
                    var content = ContentDeserializer.Deserialize(document, contentType, DocumentLanguageConstants.Global);

                    result.Add(new Option((content as INameable).Name ?? content.Id, content.Id));
                }
            }

            result = result.OrderBy(i => i.Value).ToList();

            result.Insert(0, new Option("(root)", null));

            return(result.AsReadOnly());
        }
        public IEnumerable <Option> GetAll()
        {
            var contentTypes = ContentTypeProvider.GetAll().Where(t => typeof(IHierarchical).IsAssignableFrom(t.Type));

            var documents = DocumentFinder.Find(ContainerConstants.Content).WhereIn <IContent, string>(x => x.ContentTypeId, contentTypes.Select(t => t.Id)).Select <IContent, string>(x => x.Id).Select <INameable, string>(x => x.Name).GetResultAsync().Result;

            var result = new List <Option>();

            result.Add(new Option("(root)", null));

            foreach (var document in documents)
            {
                var name = document.GlobalFacet.Interfaces.ContainsKey("INameable") &&
                           document.GlobalFacet.Interfaces["INameable"].Properties.ContainsKey("Name") &&
                           document.GlobalFacet.Interfaces["INameable"].Properties["Name"] is string?
                           (string)document.GlobalFacet.Interfaces["INameable"].Properties["Name"] :
                           document.Id;
                var option = new Option(name, document.Id);

                result.Add(option);
            }

            return(result.AsReadOnly());
        }