示例#1
0
        /// <summary>
        /// Returns a collection of blocks for a given page and block type. This will usually be one but in some cases may be more.
        /// </summary>
        /// <param name="pageGuid">The page unique identifier.</param>
        /// <param name="blockTypeGuid">The block type unique identifier.</param>
        /// <returns></returns>
        public IQueryable <Block> GetByPageAndBlockType(Guid pageGuid, Guid blockTypeGuid)
        {
            int?pageId      = PageCache.GetId(pageGuid) ?? -1;
            int?blockTypeId = BlockTypeCache.GetId(blockTypeGuid) ?? -1;

            return(GetByPageAndBlockType(pageId.Value, blockTypeId.Value));
        }
示例#2
0
        /// <summary>
        /// Determines whether [is block configured to allow retakes] [the specified assessment type list item].
        /// </summary>
        /// <param name="assessmentTypeListItem">The assessment type list item.</param>
        /// <returns>
        ///   <c>true</c> if [is block configured to allow retakes] [the specified assessment type list item]; otherwise, <c>false</c>.
        /// </returns>
        private bool IsBlockConfiguredToAllowRetakes(AssessmentTypeListItem assessmentTypeListItem)
        {
            string domain = System.Web.HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority).Replace("https://", string.Empty).Replace("http://", string.Empty);
            string route  = assessmentTypeListItem.AssessmentPath.Replace("/", string.Empty);

            var rockContext      = new RockContext();
            var pageRouteService = new PageRouteService(rockContext);
            var pageId           = pageRouteService
                                   .Queryable()
                                   .Where(r => r.Route == route)
                                   .Where(r => r.Page.Layout.Site.SiteDomains.Select(d => d.Domain == domain).FirstOrDefault())
                                   .Select(r => r.PageId)
                                   .FirstOrDefault();

            Guid blockTypeGuid = Guid.Empty;

            switch (route)
            {
            case "ConflictProfile":
                blockTypeGuid = Rock.SystemGuid.BlockType.CONFLICT_PROFILE.AsGuid();
                break;

            case "EQ":
                blockTypeGuid = Rock.SystemGuid.BlockType.EQ_INVENTORY.AsGuid();
                break;

            case "Motivators":
                blockTypeGuid = Rock.SystemGuid.BlockType.MOTIVATORS.AsGuid();
                break;

            case "SpiritualGifts":
                blockTypeGuid = Rock.SystemGuid.BlockType.GIFTS_ASSESSMENT.AsGuid();
                break;

            case "DISC":
                blockTypeGuid = Rock.SystemGuid.BlockType.DISC.AsGuid();
                break;
            }

            int?blockTypeId  = BlockTypeCache.GetId(blockTypeGuid);
            var blockService = new BlockService(rockContext);
            var block        = blockTypeGuid != Guid.Empty ? blockService.GetByPageAndBlockType(pageId, blockTypeId.Value).FirstOrDefault() : null;

            if (block != null)
            {
                block.LoadAttributes();
                return(block.GetAttributeValue("AllowRetakes").AsBooleanOrNull() ?? true);
            }

            return(true);
        }