Beispiel #1
0
        /**
         * Return the URL to display a given preview
         * @param token as received from Prismic server to identify the content to preview
         * @param linkResolver the link resolver to build URL for your site
         * @param defaultUrl the URL to default to return if the preview doesn't correspond to a document
         *                (usually the home page of your site)
         * @return the URL you should redirect the user to preview the requested change
         */
        public async Task <String> PreviewSession(String token, DocumentLinkResolver linkResolver, String defaultUrl)
        {
            var tokenJson = await this.prismicHttpClient.fetch(token, logger, cache);

            var mainDocumentId = tokenJson["mainDocument"];

            if (mainDocumentId == null)
            {
                return(defaultUrl);
            }
            var resp = await Form("everything")
                       .Query(Predicates.at("document.id", mainDocumentId.ToString()))
                       .Ref(token)
                       .Submit();

            if (resp.Results.Count == 0)
            {
                return(defaultUrl);
            }
            return(linkResolver.Resolve(resp.Results[0]));
        }
Beispiel #2
0
		/**
		* Return the URL to display a given preview
		* @param token as received from Prismic server to identify the content to preview
		* @param linkResolver the link resolver to build URL for your site
		* @param defaultUrl the URL to default to return if the preview doesn't correspond to a document
		*                (usually the home page of your site)
		* @return the URL you should redirect the user to preview the requested change
		*/
		public async Task<String> PreviewSession(String token, DocumentLinkResolver linkResolver, String defaultUrl) {
			var tokenJson = await this.prismicHttpClient.fetch(token, logger, cache);
			var mainDocumentId = tokenJson["mainDocument"];
			if (mainDocumentId == null) {
				return (defaultUrl);
			}
			var resp = await Form ("everything")
				.Query (Predicates.at ("document.id", mainDocumentId.ToString ()))
				.Ref (token)
				.Submit ();
			if (resp.Results.Count == 0) {
				return defaultUrl;
			}
			return linkResolver.Resolve (resp.Results[0]);
		}