private IEnumerable <IMember> MapDtosToContent(List <MemberDto> dtos, bool withCache = false) { var temps = new List <TempContent <Member> >(); var contentTypes = new Dictionary <int, IMemberType?>(); var content = new Member[dtos.Count]; for (var i = 0; i < dtos.Count; i++) { MemberDto dto = dtos[i]; if (withCache) { // if the cache contains the (proper version of the) item, use it IMember?cached = IsolatedCache.GetCacheItem <IMember>(RepositoryCacheKeys.GetKey <IMember, int>(dto.NodeId)); if (cached != null && cached.VersionId == dto.ContentVersionDto.Id) { content[i] = (Member)cached; continue; } } // else, need to build it // get the content type - the repository is full cache *but* still deep-clones // whatever comes out of it, so use our own local index here to avoid this var contentTypeId = dto.ContentDto.ContentTypeId; if (contentTypes.TryGetValue(contentTypeId, out IMemberType? contentType) == false) { contentTypes[contentTypeId] = contentType = _memberTypeRepository.Get(contentTypeId); } Member c = content[i] = ContentBaseFactory.BuildEntity(dto, contentType); // need properties var versionId = dto.ContentVersionDto.Id; temps.Add(new TempContent <Member>(dto.NodeId, versionId, 0, contentType, c)); } // load all properties for all documents from database in 1 query - indexed by version id IDictionary <int, PropertyCollection> properties = GetPropertyCollections(temps); // assign properties foreach (TempContent <Member> temp in temps) { if (temp.Content is not null) { temp.Content.Properties = properties[temp.VersionId]; // reset dirty initial properties (U4-1946) temp.Content.ResetDirtyProperties(false); } } return(content); }
private IMember MapDtoToContent(MemberDto dto) { var memberType = _memberTypeRepository.Get(dto.ContentDto.ContentTypeId); var member = ContentBaseFactory.BuildEntity(dto, memberType); // get properties - indexed by version id var versionId = dto.ContentVersionDto.Id; var temp = new TempContent <Member>(dto.ContentDto.NodeId, versionId, 0, memberType); var properties = GetPropertyCollections(new List <TempContent <Member> > { temp }); member.Properties = properties[versionId]; // reset dirty initial properties (U4-1946) member.ResetDirtyProperties(false); return(member); }
private IMedia MapDtoToContent(ContentDto dto) { IMediaType?contentType = _mediaTypeRepository.Get(dto.ContentTypeId); Core.Models.Media media = ContentBaseFactory.BuildEntity(dto, contentType); // get properties - indexed by version id var versionId = dto.ContentVersionDto.Id; var temp = new TempContent <Core.Models.Media>(dto.NodeId, versionId, 0, contentType); IDictionary <int, PropertyCollection> properties = GetPropertyCollections(new List <TempContent <Core.Models.Media> > { temp }); media.Properties = properties[versionId]; // reset dirty initial properties (U4-1946) media.ResetDirtyProperties(false); return(media); }