Example #1
0
        public void TestIndexValidatedSlug()
        {
            var expectedUrl = SeoHelper.ValidateSlug(this.redirectConsumerId, this.expectedUrl);
            var controller  = new AdvisorsController();
            var response    = controller.Index(this.redirectConsumerId);

            Assert.AreEqual(expectedUrl, (response as RedirectResult).Url);
            Assert.IsInstanceOfType(response, typeof(RedirectResult));
        }
        public ActionResult Index(int id = 0)
        {
            if (id == 0)
            {
                return(PageNotFoundActionResult());
            }
            if (SecurityRules.IsConsumerViewingOtherAdvisorProfile(id))
            {
                return(Request.Url != null?Redirect(AdvisorHelper.GetMyAdvisorUri + Request.Url.Query) : PageForbiddenActionResult());
            }
            string url = SeoHelper.ValidateSlug(id, Request.RawUrl);

            if (!string.IsNullOrWhiteSpace(url))
            {
                return(new RedirectResult(url, true));
            }
            var manager = new AdvisorViewManager();

            if (string.IsNullOrEmpty(ViewBag.canonicalUrl) && Request.Url != null)
            {
                ViewBag.canonicalUrl = TouchPoints.Services.HelperClasses.Url.BuildCanonicalUrl(Request.Url, Config.AppSettings.CanonicalScheme, Config.AppSettings.CanonicalHostname);
            }

            AdvisorDetailViewModel viewModel = manager.BuildAdvisorViewModel(id);

            if (viewModel == null)
            {
                return(PageNotFoundActionResult());
            }
            viewModel.InitializeBreadcrumb();


            viewModel.LoadSecurity("advisors-index", viewModel);
            GetEditBadgeSettings(viewModel);
            return(View(viewModel));
        }