コード例 #1
0
    /// <summary>
    ///     Builds an IContent item from a dto and content type.
    /// </summary>
    public static Content BuildEntity(DocumentDto dto, IContentType?contentType)
    {
        ContentDto         contentDto          = dto.ContentDto;
        NodeDto            nodeDto             = contentDto.NodeDto;
        DocumentVersionDto documentVersionDto  = dto.DocumentVersionDto;
        ContentVersionDto  contentVersionDto   = documentVersionDto.ContentVersionDto;
        DocumentVersionDto?publishedVersionDto = dto.PublishedVersionDto;

        var content = new Content(nodeDto.Text, nodeDto.ParentId, contentType);

        try
        {
            content.DisableChangeTracking();

            content.Id        = dto.NodeId;
            content.Key       = nodeDto.UniqueId;
            content.VersionId = contentVersionDto.Id;

            content.Name = contentVersionDto.Text;

            content.Path      = nodeDto.Path;
            content.Level     = nodeDto.Level;
            content.ParentId  = nodeDto.ParentId;
            content.SortOrder = nodeDto.SortOrder;
            content.Trashed   = nodeDto.Trashed;

            content.CreatorId  = nodeDto.UserId ?? Constants.Security.UnknownUserId;
            content.WriterId   = contentVersionDto.UserId ?? Constants.Security.UnknownUserId;
            content.CreateDate = nodeDto.CreateDate;
            content.UpdateDate = contentVersionDto.VersionDate;

            content.Published = dto.Published;
            content.Edited    = dto.Edited;

            // TODO: shall we get published infos or not?
            // if (dto.Published)
            if (publishedVersionDto != null)
            {
                content.PublishedVersionId = publishedVersionDto.Id;
                content.PublishDate        = publishedVersionDto.ContentVersionDto.VersionDate;
                content.PublishName        = publishedVersionDto.ContentVersionDto.Text;
                content.PublisherId        = publishedVersionDto.ContentVersionDto.UserId;
            }

            // templates = ignored, managed by the repository

            // reset dirty initial properties (U4-1946)
            content.ResetDirtyProperties(false);
            return(content);
        }
        finally
        {
            content.EnableChangeTracking();
        }
    }
コード例 #2
0
        // always build the current / VersionPk dto
        // we're never going to build / save old versions (which are immutable)
        private static DocumentVersionDto BuildDocumentVersionDto(IContent entity, ContentDto contentDto)
        {
            var dto = new DocumentVersionDto
            {
                Id         = entity.VersionId,
                TemplateId = entity.TemplateId,
                Published  = false, // always building the current, unpublished one

                ContentVersionDto = BuildContentVersionDto(entity, contentDto)
            };

            return(dto);
        }