Esempio n. 1
0
        private IEnumerable <IMember> ProcessQuery(Sql sql)
        {
            //NOTE: This doesn't allow properties to be part of the query
            var dtos = Database.Fetch <MemberDto, ContentVersionDto, ContentDto, NodeDto>(sql);

            var ids = dtos.Select(x => x.ContentVersionDto.ContentDto.ContentTypeId).ToArray();

            //content types
            var contentTypes = ids.Length == 0 ? Enumerable.Empty <IMemberType>() : _memberTypeRepository.GetAll(ids).ToArray();

            var dtosWithContentTypes = dtos
                                       //This select into and null check are required because we don't have a foreign damn key on the contentType column
                                       // http://issues.umbraco.org/issue/U4-5503
                                       .Select(x => new { dto = x, contentType = contentTypes.FirstOrDefault(ct => ct.Id == x.ContentVersionDto.ContentDto.ContentTypeId) })
                                       .Where(x => x.contentType != null)
                                       .ToArray();

            //Go get the property data for each document
            IEnumerable <DocumentDefinition> docDefs = dtosWithContentTypes.Select(d => new DocumentDefinition(
                                                                                       d.dto.NodeId,
                                                                                       d.dto.ContentVersionDto.VersionId,
                                                                                       d.dto.ContentVersionDto.VersionDate,
                                                                                       d.dto.ContentVersionDto.ContentDto.NodeDto.CreateDate,
                                                                                       d.contentType));

            var propertyData = GetPropertyCollection(sql, docDefs);

            return(dtosWithContentTypes.Select(d => CreateMemberFromDto(
                                                   d.dto,
                                                   contentTypes.First(ct => ct.Id == d.dto.ContentVersionDto.ContentDto.ContentTypeId),
                                                   propertyData[d.dto.NodeId])));
        }
Esempio n. 2
0
        private IEnumerable <IMember> BuildFromDtos(List <MemberReadOnlyDto> dtos)
        {
            if (dtos == null || dtos.Any() == false)
            {
                return(Enumerable.Empty <IMember>());
            }

            //We assume that there won't exist a lot of MemberTypes, so the following should be fairly fast
            var memberTypes    = new Dictionary <string, IMemberType>();
            var memberTypeList = _memberTypeRepository.GetAll();

            memberTypeList.ForEach(x => memberTypes.Add(x.Alias, x));

            var factory = new MemberReadOnlyFactory(memberTypes);

            return(dtos.Select(factory.BuildEntity));
        }