private ActionResult GetPage(string viewName, string viewFolder, string urlKey,
            PageType pageType)
        {
            InitPageModel();
      
            profileDetails = new ProfileDetailsBuilder(urlKey).Build();

            if (profileDetails == null)
            {

                ErrorController.InvokeHttp404(HttpContext);
                return new EmptyResult();
            }

            if (AccessControlHelper.ShouldDenyAccess(profileDetails))
            {
                return AccessControlHelper.GetAccessNotAllowedActionResult();
            }

            PageModel.PageTitle = profileDetails.Title;

            ConfigureWithProfile(profileDetails);

            if (PageModel.HasExclusiveSkin == false)
            {
                PageModel.Skin.PartialViewFolder = viewFolder;
            }

            PageModel.PageType = pageType;
            PageModel.DisplayProfileTitle = true;

            return View(PageModel.GetSkinView(viewName), PageModel);
        }
        /// <summary>
        /// Whether a user should be denied access to a profile
        /// </summary>
        public static bool ShouldDenyAccess(ProfileDetails details)
        {
            if (AppConfig.Instance.IsAccessControlToProfiles == false)
            {
                return false;
            }

            return UserDetails.CurrentUser()
                .IsUserMemberOfAccessControlGroup(details.AccessControlGroup) == false;
        }
        public ActionResult Data(string leadProfileUrlKey, string profileUrlKey)
        {
            InitPageModel();
            PageModel.PageType = PageType.DataPageOfProfileWithFrontPage;
            details = new ProfileDetailsBuilder(profileUrlKey).Build();

            if (AccessControlHelper.ShouldDenyAccess(details))
            {
                return AccessControlHelper.GetAccessNotAllowedActionResult();
            }

            return GetView(leadProfileUrlKey, "Data");
        }
        public ActionResult FrontPage(string leadProfileUrlKey)
        {
            InitPageModel();
            PageModel.PageType = PageType.ProfileCollectionFrontPage;
            details = new ProfileDetailsBuilder(leadProfileUrlKey).Build();

            if (AccessControlHelper.ShouldDenyAccess(details))
            {
                return AccessControlHelper.GetAccessNotAllowedActionResult();
            }

            return GetView(leadProfileUrlKey, "FrontPage");
        }
        private void CreateProfileDetails(int profileId)
        {
            profileReader = ReaderFactory.GetProfileReader();
            details = profileReader.GetProfileDetails(profileId);
            if (details != null)
            {
                details.Id = profileId;
                AssignDomains();

                // Parse string lists
                details.ExtraJavaScriptFiles = ParseStringList(details.ExtraJavaScriptFilesString);
                details.ExtraCssFiles = ParseStringList(details.ExtraCssFilesString);
            }
        }
        private void CreateProfileDetails(string profileKey)
        {
            profileReader = ReaderFactory.GetProfileReader();
            details = profileReader.GetProfileDetails(profileKey);
            if (details != null)
            {
                details.ProfileUrlKey = profileKey;
                AssignDomains();

                // Parse string lists
                details.ExtraJavaScriptFiles = ParseStringList(details.ExtraJavaScriptFilesString);
                details.ExtraCssFiles = ParseStringList(details.ExtraCssFilesString);
            }
            else if (string.IsNullOrEmpty(profileKey) == false)
            {
                
                throw new FingertipsException("Profile could not be found: " + profileKey);
            }
        }
        public void SetProfileCollection(ProfileDetails details, string leadProfileUrlKey)
        {
            ViewBag.IsPageRootProfileCollection = true;
            ViewBag.LeadProfileUrlKey = leadProfileUrlKey;

            // Get appropriate profile details
            var profileDetails = details.ProfileUrlKey == leadProfileUrlKey
                ? details
                : new ProfileDetailsBuilder(leadProfileUrlKey).Build();

            var profileCollectionBuilder = new ProfileCollectionBuilder(ReaderFactory.GetProfileReader(), appConfig);

            PageModel.ProfileCollections = new ProfileCollectionListBuilder(profileCollectionBuilder)
                .GetProfileCollections(leadProfileUrlKey, profileDetails.ProfileCollectionIds);
        }
 protected void AssignDomainHeadings(ProfileDetails details)
 {
     if (details.HasDomains)
     {
         ViewBag.DomainHeadings = details.Domains;
     }
 }
        private void ConfigureLongerLivesProfile(ProfileDetails details)
        {
            var longerLivesDetails = details.LongerLivesProfileDetails;

            ViewBag.LongerLivesSupportingProfileId =
                longerLivesDetails.SupportingProfileId;

            ViewBag.SupportingGroupId =
                ReaderFactory.GetProfileReader().GetDomainIds(longerLivesDetails.SupportingProfileDetails.Id).ToArray();

            ViewBag.RankingsMiddleColumnGroup = details.Domains[longerLivesDetails.DomainsToDisplay];
            ViewBag.DefaultGroupId = details.Domains[0].GroupId;

            ViewBag.HasPracticeData = JsHelper.GetJsBool(longerLivesDetails.HasPracticeData);

            ViewBag.LongerLivesExtraJsFiles =
                ProfileDetailsBuilder.ParseStringList(longerLivesDetails.ExtraJsFiles);

            ViewBag.Title = longerLivesDetails.Title;
            ViewBag.DomainsToDisplay = longerLivesDetails.DomainsToDisplay;

        }
        protected void ConfigureWithProfile(ProfileDetails details)
        {
            ViewBag.ProfileDetails = details;
            ViewBag.ProfileUrlKey = details.ProfileUrlKey;

            if (PageModel != null)
            {
                PageModel.ProfileId = details.Id;
                PageModel.TemplateProfileId = details.Id;
                AssignDomainHeadings(details);
                ViewBag.AvailableDomains = details.Domains;
                ViewData["groupIds"] = details.Domains.Select(x => x.GroupId).ToArray();

                if (details.LongerLivesProfileDetails != null)
                {
                    ConfigureLongerLivesProfile(details);
                }
                else
                {
                    // Fingertips profile
                    ViewBag.Title = details.Title;
                }

                PageModel.PageTitle = details.Title;

                ViewBag.DefaultAreaType = details.DefaultAreaType;
                PageModel.RagColourId = details.RagColourId;
                PageModel.StartZeroYAxis = details.StartZeroYAxis;
                PageModel.DefaultFingertipsTabId = details.DefaultFingertipsTabId;
                PageModel.HasRecentTrends = details.HasRecentTrends;
                PageModel.UseTargetBenchmarkByDefault = details.UseTargetBenchmarkByDefault;
                PageModel.AreAnyPdfsForProfile = details.ArePdfs;

                ViewBag.EnumParentDisplay = details.EnumParentDisplay;
                ViewBag.ExtraJsFiles = details.ExtraJavaScriptFiles;
                ViewBag.ExtraCssFiles = details.ExtraCssFiles;

                PageModel.IgnoredSpineChartAreas = details.AreasToIgnoreForSpineCharts;
                PageModel.HasExclusiveSkin = details.HasExclusiveSkin;
                PageModel.YearRange = details.Id == ProfileIds.HealthInequalities
                                          ? new YearRange { StartYear = 2005, EndYear = 2008 }
                                          : null;
                ViewBag.ShowDataQuality = details.ShowDataQuality.ToString().ToLower();
                ViewBag.IsNational = details.IsNational.ToString().ToLower();

                ViewBag.FingertipsUrl = new FingertipsUrl(appConfig).Host;
                PageModel.IsOfficialStatistics = details.IsOfficialStatistics;
                PageModel.IsProfileWithOnlyStaticReports = details.IsProfileWithOnlyStaticReports;
                ViewBag.StaticReportsTimePeriods = details.StaticReportsTimePeriods ?? string.Empty;

                PageModel.SpineChartMinMaxLabel = new SpineChartMinMaxLabelBuilder(
                    details.SpineChartMinMaxLabel, 
                    PageModel.RagColourId
                    ).MinMaxLabels;
            }
        }