/// <summary>
        /// Maps an EF PageTemplate record from the db into an PageTemplateSummary
        /// object. If the db record is null then null is returned.
        /// </summary>
        /// <param name="queryModel">Query model with data from the database.</param>
        public virtual PageTemplateSummary Map(PageTemplateSummaryQueryModel queryModel)
        {
            var dbPageTemplate = queryModel?.PageTemplate;

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

            var pageTemplate = new PageTemplateSummary()
            {
                IsArchived     = dbPageTemplate.IsArchived,
                Name           = dbPageTemplate.Name,
                PageTemplateId = dbPageTemplate.PageTemplateId,
                CreateDate     = DbDateTimeMapper.AsUtc(dbPageTemplate.CreateDate),
                Description    = dbPageTemplate.Description,
                FileName       = dbPageTemplate.FileName,
                PageType       = (PageType)dbPageTemplate.PageTypeId,
                UpdateDate     = DbDateTimeMapper.AsUtc(dbPageTemplate.UpdateDate),
                NumPages       = queryModel.NumPages,
                NumRegions     = queryModel.NumRegions
            };

            return(pageTemplate);
        }
Exemple #2
0
        private CustomEntityDetails MapInitialData(CustomEntityVersion dbVersion, IExecutionContext executionContext)
        {
            var entity = new CustomEntityDetails()
            {
                CustomEntityId = dbVersion.CustomEntity.CustomEntityId,
                UrlSlug        = dbVersion.CustomEntity.UrlSlug,
                PublishStatus  = PublishStatusMapper.FromCode(dbVersion.CustomEntity.PublishStatusCode),
                PublishDate    = DbDateTimeMapper.AsUtc(dbVersion.CustomEntity.PublishDate),
            };

            entity.AuditData = _auditDataMapper.MapCreateAuditData(dbVersion.CustomEntity);

            entity.LatestVersion = new CustomEntityVersionDetails()
            {
                CustomEntityVersionId = dbVersion.CustomEntityVersionId,
                Title          = dbVersion.Title,
                DisplayVersion = dbVersion.DisplayVersion,
                WorkFlowStatus = (WorkFlowStatus)dbVersion.WorkFlowStatusId
            };

            entity.LatestVersion.AuditData = _auditDataMapper.MapCreateAuditData(dbVersion);
            entity.HasDraftVersion         = entity.LatestVersion.WorkFlowStatus == WorkFlowStatus.Draft;

            return(entity);
        }
Exemple #3
0
        /// <summary>
        /// Maps an EF PageTemplate record from the db into an PageTemplateDetailsMapper
        /// object. If the db record is null then null is returned.
        /// </summary>
        /// <param name="queryModel">Query data returned from the database.</param>
        public virtual PageTemplateDetails Map(PageTemplateDetailsQueryModel queryModel)
        {
            var dbPageTemplate = queryModel?.PageTemplate;

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

            var pageTemplate = new PageTemplateDetails()
            {
                FullPath               = dbPageTemplate.FullPath,
                IsArchived             = dbPageTemplate.IsArchived,
                Name                   = dbPageTemplate.Name,
                PageTemplateId         = dbPageTemplate.PageTemplateId,
                CreateDate             = DbDateTimeMapper.AsUtc(dbPageTemplate.CreateDate),
                Description            = dbPageTemplate.Description,
                FileName               = dbPageTemplate.FileName,
                PageType               = (PageType)dbPageTemplate.PageTypeId,
                CustomEntityModelType  = dbPageTemplate.CustomEntityModelType,
                UpdateDate             = DbDateTimeMapper.AsUtc(dbPageTemplate.UpdateDate),
                NumPages               = queryModel.NumPages,
                CustomEntityDefinition = queryModel.CustomEntityDefinition
            };

            pageTemplate.Regions = queryModel
                                   .PageTemplate
                                   .PageTemplateRegions
                                   .Select(MapRegion)
                                   .ToList();

            return(pageTemplate);
        }
Exemple #4
0
        /// <summary>
        /// Updates an UpdateAuditData object  using the creator information from the model as the updater
        /// information. Useful when you are mapping audit information from two different objects. If the
        /// db record is null then an ArgumentNullException is thrown.
        /// </summary>
        /// <param name="model">ICreateAuditable EF database record to map create data from.</param>
        public virtual void MapUpdateAuditDataUpdaterData(UpdateAuditData updateAuditDatra, ICreateAuditable model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }
            ValidateUserProperty(model.Creator, nameof(model.Creator));

            updateAuditDatra.UpdateDate = DbDateTimeMapper.AsUtc(model.CreateDate);
            updateAuditDatra.Updater    = _userMicroSummaryMapper.Map(model.Creator);
        }
Exemple #5
0
        /// <summary>
        /// Maps an EF CustomEntity record from the db into a CustomEntityRoute object. If the
        /// db record is null then null is returned.
        /// </summary>
        /// <param name="dbCustomEntity">CustomEntity record from the database.</param>
        /// <param name="locale">Locale to map to the object.</param>
        public CustomEntityRoute Map(
            CustomEntity dbCustomEntity,
            ActiveLocale locale
            )
        {
            if (dbCustomEntity == null)
            {
                throw new ArgumentNullException(nameof(dbCustomEntity));
            }
            if (dbCustomEntity.CustomEntityVersions == null)
            {
                throw new ArgumentNullException(nameof(dbCustomEntity.CustomEntityVersions));
            }

            var route = new CustomEntityRoute()
            {
                CustomEntityDefinitionCode = dbCustomEntity.CustomEntityDefinitionCode,
                CustomEntityId             = dbCustomEntity.CustomEntityId,
                UrlSlug       = dbCustomEntity.UrlSlug,
                Locale        = locale,
                PublishDate   = DbDateTimeMapper.AsUtc(dbCustomEntity.PublishDate),
                PublishStatus = dbCustomEntity.PublishStatusCode == PublishStatusCode.Published ? PublishStatus.Published : PublishStatus.Unpublished,
                Ordering      = dbCustomEntity.Ordering
            };

            bool hasLatestPublishVersion = false;

            route.Versions = new List <CustomEntityVersionRoute>();

            foreach (var dbVersion in dbCustomEntity
                     .CustomEntityVersions
                     .OrderByLatest())
            {
                var version = new CustomEntityVersionRoute()
                {
                    CreateDate     = DbDateTimeMapper.AsUtc(dbVersion.CreateDate),
                    Title          = dbVersion.Title,
                    VersionId      = dbVersion.CustomEntityVersionId,
                    WorkFlowStatus = (WorkFlowStatus)dbVersion.WorkFlowStatusId
                };

                if (!hasLatestPublishVersion && version.WorkFlowStatus == WorkFlowStatus.Published)
                {
                    version.IsLatestPublishedVersion = true;
                    hasLatestPublishVersion          = true;
                }
                route.Versions.Add(version);
            }

            route.HasDraftVersion     = route.Versions.Any(v => v.WorkFlowStatus == WorkFlowStatus.Draft);
            route.HasPublishedVersion = route.Versions.Any(v => v.WorkFlowStatus == WorkFlowStatus.Published);

            return(route);
        }
Exemple #6
0
 protected PageTemplateRegionDetails MapRegion(PageTemplateRegion dbRegion)
 {
     return(new PageTemplateRegionDetails()
     {
         CreateDate = DbDateTimeMapper.AsUtc(dbRegion.CreateDate),
         IsCustomEntityRegion = dbRegion.IsCustomEntityRegion,
         Name = dbRegion.Name,
         PageTemplateId = dbRegion.PageTemplateId,
         PageTemplateRegionId = dbRegion.PageTemplateRegionId,
         UpdateDate = DbDateTimeMapper.AsUtc(dbRegion.UpdateDate)
     });
 }
Exemple #7
0
        /// <summary>
        /// Maps an EF model that inherits from ICreateAuditable into a UpdateAuditData object
        /// using only the creator information from the model. Useful when you are mapping audit
        /// information from two different objects. If the db record is null then an ArgumentNullException is thrown.
        /// </summary>
        /// <param name="model">ICreateAuditable EF database record to map create data from.</param>
        public virtual UpdateAuditData MapUpdateAuditDataCreatorData(ICreateAuditable model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }
            ValidateUserProperty(model.Creator, nameof(model.Creator));

            var auditData = new UpdateAuditData();

            auditData.CreateDate = DbDateTimeMapper.AsUtc(model.CreateDate);
            auditData.Creator    = _userMicroSummaryMapper.Map(model.Creator);

            return(auditData);
        }
Exemple #8
0
        /// <summary>
        /// Maps an EF DocumentAsset record from the db into a DocumentAssetDetails
        /// object. If the db record is null then null is returned.
        /// </summary>
        /// <param name="dbDocument">DocumentAsset record from the database.</param>
        public DocumentAssetDetails Map(DocumentAsset dbDocument)
        {
            if (dbDocument == null)
            {
                return(null);
            }

            var document = new DocumentAssetDetails();

            _documentAssetSummaryMapper.Map(document, dbDocument);
            document.Description    = dbDocument.Description;
            document.FileUpdateDate = DbDateTimeMapper.AsUtc(dbDocument.FileUpdateDate);

            return(document);
        }
Exemple #9
0
        /// <summary>
        /// Maps an EF user record from the db into a UserDetails object. If the
        /// db record is null then null is returned.
        /// </summary>
        /// <param name="dbUser">User record from the database.</param>
        public virtual UserDetails Map(User dbUser)
        {
            if (dbUser == null)
            {
                return(null);
            }

            if (dbUser.Role == null)
            {
                throw new ArgumentException("dbUser.Role must be included in the query to map to use the UserDetailsMapper");
            }

            var user = new UserDetails()
            {
                Email                  = dbUser.Email,
                FirstName              = dbUser.FirstName,
                LastName               = dbUser.LastName,
                UserId                 = dbUser.UserId,
                Username               = dbUser.Username,
                LastLoginDate          = DbDateTimeMapper.AsUtc(dbUser.LastLoginDate),
                LastPasswordChangeDate = DbDateTimeMapper.AsUtc(dbUser.LastPasswordChangeDate),
                RequirePasswordChange  = dbUser.RequirePasswordChange
            };

            user.AuditData = new CreateAuditData()
            {
                CreateDate = DbDateTimeMapper.AsUtc(dbUser.CreateDate)
            };

            if (dbUser.Creator != null)
            {
                user.AuditData.Creator = _userMicroSummaryMapper.Map(dbUser.Creator);
            }

            var userArea = _userAreaRepository.GetByCode(dbUser.UserAreaCode);

            EntityNotFoundException.ThrowIfNull(userArea, dbUser.UserAreaCode);

            user.UserArea = new UserAreaMicroSummary()
            {
                UserAreaCode = dbUser.UserAreaCode,
                Name         = userArea.Name
            };

            user.Role = _roleDetailsMapper.Map(dbUser.Role);

            return(user);
        }
        /// <summary>
        /// Maps an EF user record from the db into a UserAccountDetails object. If the
        /// db record is null then null is returned.
        /// </summary>
        /// <param name="dbUser">User record from the database.</param>
        public virtual UserAccountDetails Map(User dbUser)
        {
            if (dbUser == null)
            {
                return(null);
            }

            var user = new UserAccountDetails()
            {
                Email                  = dbUser.Email,
                FirstName              = dbUser.FirstName,
                LastName               = dbUser.LastName,
                UserId                 = dbUser.UserId,
                Username               = dbUser.Username,
                LastLoginDate          = DbDateTimeMapper.AsUtc(dbUser.LastLoginDate),
                LastPasswordChangeDate = DbDateTimeMapper.AsUtc(dbUser.LastPasswordChangeDate),
                PreviousLoginDate      = DbDateTimeMapper.AsUtc(dbUser.PreviousLoginDate),
                RequirePasswordChange  = dbUser.RequirePasswordChange
            };

            user.AuditData = new CreateAuditData()
            {
                CreateDate = DbDateTimeMapper.AsUtc(dbUser.CreateDate)
            };

            if (dbUser.Creator != null)
            {
                user.AuditData.Creator = _userMicroSummaryMapper.Map(dbUser.Creator);
            }

            var userArea = _userAreaRepository.GetByCode(dbUser.UserAreaCode);

            EntityNotFoundException.ThrowIfNull(userArea, dbUser.UserAreaCode);

            user.UserArea = new UserAreaMicroSummary()
            {
                UserAreaCode = dbUser.UserAreaCode,
                Name         = userArea.Name
            };

            return(user);
        }
        private CustomEntityRenderSummary MapCore(CustomEntityVersion dbResult)
        {
            var entity = new CustomEntityRenderSummary()
            {
                CreateDate = DbDateTimeMapper.AsUtc(dbResult.CreateDate),
                CustomEntityDefinitionCode = dbResult.CustomEntity.CustomEntityDefinitionCode,
                CustomEntityId             = dbResult.CustomEntityId,
                CustomEntityVersionId      = dbResult.CustomEntityVersionId,
                Ordering       = dbResult.CustomEntity.Ordering,
                Title          = dbResult.Title,
                UrlSlug        = dbResult.CustomEntity.UrlSlug,
                WorkFlowStatus = (WorkFlowStatus)dbResult.WorkFlowStatusId,
                PublishDate    = DbDateTimeMapper.AsUtc(dbResult.CustomEntity.PublishDate)
            };

            entity.PublishStatus = PublishStatusMapper.FromCode(dbResult.CustomEntity.PublishStatusCode);
            entity.Model         = _customEntityDataModelMapper.Map(dbResult.CustomEntity.CustomEntityDefinitionCode, dbResult.SerializedData);

            return(entity);
        }
        private CustomEntitySummary MapBasicProperties(CustomEntityPublishStatusQuery dbStatusQuery)
        {
            var entity = new CustomEntitySummary()
            {
                AuditData = _auditDataMapper.MapUpdateAuditDataCreatorData(dbStatusQuery.CustomEntity),
                CustomEntityDefinitionCode = dbStatusQuery.CustomEntity.CustomEntityDefinitionCode,
                CustomEntityId             = dbStatusQuery.CustomEntityId,
                HasDraftVersion            = dbStatusQuery.CustomEntityVersion.WorkFlowStatusId == (int)WorkFlowStatus.Draft,
                // note that if this is not a published version, we do further checks on this later in the process
                HasPublishedVersion = dbStatusQuery.CustomEntityVersion.WorkFlowStatusId == (int)WorkFlowStatus.Published,
                PublishStatus       = PublishStatusMapper.FromCode(dbStatusQuery.CustomEntity.PublishStatusCode),
                PublishDate         = DbDateTimeMapper.AsUtc(dbStatusQuery.CustomEntity.PublishDate),
                Ordering            = dbStatusQuery.CustomEntity.Ordering,
                Title   = dbStatusQuery.CustomEntityVersion.Title,
                UrlSlug = dbStatusQuery.CustomEntity.UrlSlug
            };

            _auditDataMapper.MapUpdateAuditDataUpdaterData(entity.AuditData, dbStatusQuery.CustomEntityVersion);
            return(entity);
        }
Exemple #13
0
        private CustomEntityRenderDetails MapCustomEntity(CustomEntityVersion dbResult, IExecutionContext executionContext)
        {
            _permissionValidationService.EnforceCustomEntityPermission <CustomEntityReadPermission>(dbResult.CustomEntity.CustomEntityDefinitionCode, executionContext.UserContext);

            var entity = new CustomEntityRenderDetails()
            {
                CreateDate = DbDateTimeMapper.AsUtc(dbResult.CreateDate),
                CustomEntityDefinitionCode = dbResult.CustomEntity.CustomEntityDefinitionCode,
                CustomEntityId             = dbResult.CustomEntityId,
                CustomEntityVersionId      = dbResult.CustomEntityVersionId,
                Ordering       = dbResult.CustomEntity.Ordering,
                Title          = dbResult.Title,
                UrlSlug        = dbResult.CustomEntity.UrlSlug,
                WorkFlowStatus = (WorkFlowStatus)dbResult.WorkFlowStatusId,
                PublishDate    = DbDateTimeMapper.AsUtc(dbResult.CustomEntity.PublishDate)
            };

            entity.PublishStatus = PublishStatusMapper.FromCode(dbResult.CustomEntity.PublishStatusCode);
            entity.Model         = _customEntityDataModelMapper.Map(dbResult.CustomEntity.CustomEntityDefinitionCode, dbResult.SerializedData);

            return(entity);
        }
        private IQueryable <PageQueryResult> QueryPages()
        {
            var dbPages = _dbContext
                          .Pages
                          .AsNoTracking()
                          .FilterActive()
                          .Select(p => new PageQueryResult()
            {
                RoutingInfo = new PageRoute()
                {
                    PageId   = p.PageId,
                    UrlPath  = p.UrlPath,
                    PageType = (PageType)p.PageTypeId,
                    CustomEntityDefinitionCode = p.CustomEntityDefinitionCode,
                    PublishDate   = DbDateTimeMapper.AsUtc(p.PublishDate),
                    PublishStatus = PublishStatusMapper.FromCode(p.PublishStatusCode)
                },
                LocaleId        = p.LocaleId,
                PageDirectoryId = p.PageDirectoryId
            });

            return(dbPages);
        }
        private PageVersionRoute MapVersion(
            PageRoute routingInfo,
            PageVersionQueryResult version,
            Dictionary <int, PageTemplateQueryResult> templates
            )
        {
            var versionRouting = new PageVersionRoute();

            versionRouting.WorkFlowStatus = (WorkFlowStatus)version.WorkFlowStatusId;
            versionRouting.Title          = version.Title;
            versionRouting.CreateDate     = DbDateTimeMapper.AsUtc(version.CreateDate);
            versionRouting.VersionId      = version.PageVersionId;

            var template = templates.GetOrDefault(version.PageTemplateId);

            if (template != null)
            {
                versionRouting.PageTemplateId         = version.PageTemplateId;
                versionRouting.HasCustomEntityRegions = template.HasCustomEntityRegions;
                versionRouting.HasPageRegions         = template.HasPageRegions;
            }

            return(versionRouting);
        }