Пример #1
0
        /// <summary>
        /// This method takes nice url, for instance /Home/Article/my_first_article and returns appropriate articleId from the database.
        /// In case of failure returns -1;
        /// </summary>
        /// <param name="inputURL"></param>
        /// <param name="dataService"></param>
        /// <returns></returns>
        public static int ReturnArticleIdFromNiceUrl(string inputURL, IJasperDataServicePublic dataService)
        {
            try
            {
                inputURL = UrlRewriting.NormalizeUrl(inputURL);

                // mydomain.cz + /Home/Articles
                string articlesRoute = UrlRewriting.NormalizeUrl(Configuration.WebsiteConfig.ArticleRoute);

                if (inputURL.StartsWith(articlesRoute))
                {
                    int ix = inputURL.IndexOf(articlesRoute);
                    if (ix != -1)
                    {
                        string requestedArticleUrl = inputURL.Substring(ix + articlesRoute.Length);

                        // database stores URL without slashes:
                        requestedArticleUrl = requestedArticleUrl.Replace("/", "");

                        requestedArticleUrl = requestedArticleUrl.Replace("%20", " "); // in case custom URL contains space (in DB is space not saved as %20)
                        int articleId = dataService.Database.UrlRewrite.Where(ur => ur.Url == requestedArticleUrl).Select(s => s.ArticleId).Single();

                        //  string relativeUrl= inputURL.Replace(requestedArticleUrl, "?id=" + articleId);

                        return(articleId);
                    }
                    else
                    {
                        return(-1);
                    }
                }
                else
                {
                    return(-1);
                }
            }
            catch
            {
                return(-1);
            }
        }
Пример #2
0
 // HomeController catches all requests coming from /Home/*
 public HomeController(IJasperDataServicePublic dataServicePublic)
 {
     this._dataServicePublic = dataServicePublic;
 }