Example #1
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);
        }
Example #2
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>
        /// <param name="routingDataProperties">Collection of data properties to map to the routing parameters collection.</param>
        public CustomEntityRoute Map(
            CustomEntity dbCustomEntity,
            ActiveLocale locale
            )
        {
            if (dbCustomEntity == null)
            {
                throw new ArgumentNullException(nameof(dbCustomEntity));
            }

            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
            };

            var versions = new List <CustomEntityVersionRoute>();

            route.Versions = versions;

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

            return(route);
        }
Example #3
0
        public CustomEntityRouteDataBuilderParameter(
            CustomEntityRoute customEntityRoute,
            CustomEntityVersionRoute customEntityVersionRoute,
            TDataModel dataModel
            )
        {
            if (customEntityRoute == null)
            {
                throw new ArgumentNullException(nameof(customEntityRoute));
            }
            if (customEntityVersionRoute == null)
            {
                throw new ArgumentNullException(nameof(customEntityVersionRoute));
            }
            if (dataModel == null)
            {
                throw new ArgumentNullException(nameof(dataModel));
            }

            _customEntityRoute        = customEntityRoute;
            _customEntityVersionRoute = customEntityVersionRoute;
            _dataModel = dataModel;
        }