コード例 #1
0
        //EndDocSection:Constructor

        //DocSection:DisplayConsent
        public ActionResult DisplayConsent()
        {
            // Gets the related tracking consent
            // Fill in the code name of the appropriate consent object in Kentico
            ConsentInfo consent = ConsentInfoProvider.GetConsentInfo("SampleTrackingConsent");

            // Gets the current contact
            ContactInfo currentContact = ContactManagementContext.GetCurrentContact();

            // Sets the default cookie level for contacts who have revoked the tracking consent
            // Required for scenarios where one contact uses multiple browsers
            if ((currentContact != null) && !consentAgreementService.IsAgreed(currentContact, consent))
            {
                var defaultCookieLevel = currentCookieLevelProvider.GetDefaultCookieLevel();
                currentCookieLevelProvider.SetCurrentCookieLevel(defaultCookieLevel);
            }

            var consentModel = new TrackingConsentViewModel
            {
                // Adds the consent's short text to the model
                ShortText = consent.GetConsentText("en-US").ShortText,

                // Checks whether the current contact has given an agreement for the tracking consent
                IsAgreed = (currentContact != null) && consentAgreementService.IsAgreed(currentContact, consent)
            };

            return(View("Consent", consentModel));
        }
コード例 #2
0
        public IViewComponentResult Invoke()
        {
            var consent = consentInfoProvider.Get(TrackingConsentGenerator.CONSENT_NAME);

            if (consent != null)
            {
                var consentModel = new ConsentViewModel
                {
                    ConsentShortText = consent.GetConsentText(System.Threading.Thread.CurrentThread.CurrentUICulture.Name).ShortText
                };

                var contact = CMS.ContactManagement.ContactManagementContext.CurrentContact;
                if ((contact != null) && consentAgreementService.IsAgreed(contact, consent))
                {
                    consentModel.IsConsentAgreed = true;
                }

                return(View("~/Components/ViewComponents/TrackingConsent/_TrackingConsent.cshtml", consentModel));
            }

            return(Content(string.Empty));
        }
コード例 #3
0
        // GET: Consent
        public ActionResult Index()
        {
            var consent = ConsentInfoProvider.GetConsentInfo(TrackingConsentGenerator.CONSENT_NAME);

            if (consent != null)
            {
                var model = new ConsentViewModel
                {
                    ConsentShortText = consent.GetConsentText(Thread.CurrentThread.CurrentUICulture.Name).ShortText
                };

                var contact = ContactManagementContext.CurrentContact;
                if ((contact != null) && mConsentAgreementService.IsAgreed(contact, consent))
                {
                    model.IsConsentAgreed = true;
                }

                return(PartialView("_TrackingConsent", model));
            }

            return(new EmptyResult());
        }