コード例 #1
0
ファイル: BlogController.cs プロジェクト: nduas/Website
        public virtual ActionResult View(int month, int year, string slug)
        {
            PostModel post;

            try
            {
                post = _blogRepository.GetBySlug(slug);
            }
            catch (EntityNotFoundException)
            {
                // Throw a 404 if the post doesn't exist
                return(NotFound());
            }

            // Check the URL was actually correct (year and month), redirect if not.
            if (year != post.Date.Year || month != post.Date.Month)
            {
                return(RedirectPermanent(Url.BlogPost(post)));
            }

            // Set last-modified date based on the date of the post
            Response.Headers["Last-Modified"] = post.Date.ToUniversalTime().ToString("R");

            return(View(new PostViewModel
            {
                Post = post,
                PostCategories = _blogRepository.CategoriesForPost(post),
                PostTags = _blogRepository.TagsForPost(post),
                ShortUrl = Url.Action("ShortUrl", "Blog", new { Alias = _urlShortener.Shorten(post) }, Request.Scheme),
                SocialNetworks = GetSocialNetworks(post),
                Comments = _commentRepository.GetCommentsTree(post)
            }));
        }
コード例 #2
0
        public virtual ActionResult View(int month, int year, string slug)
        {
            PostModel post;

            try
            {
                post = _blogRepository.GetBySlug(slug);
            }
            catch (EntityNotFoundException)
            {
                // Throw a 404 if the post doesn't exist
                return(HttpNotFound(string.Format("Blog post '{0}' not found.", slug)));
            }

            // Check the URL was actually correct (year and month), redirect if not.
            if (year != post.Date.Year || month != post.Date.Month)
            {
                return(RedirectPermanent(Url.BlogPost(post)));
            }

            // Set last-modified date based on the date of the post
            Response.Cache.SetLastModified(post.Date);

            return(View(new PostViewModel
            {
                Post = post,
                PostCategories = _blogRepository.CategoriesForPost(post),
                PostTags = _blogRepository.TagsForPost(post),
                ShortUrl = Url.Action(MVC.Blog.ShortUrl(_urlShortener.Shorten(post)), "http"),
                SocialNetworks = GetSocialNetworks(post),
                Comments = _commentRepository.GetCommentsTree(post)
            }));
        }
コード例 #3
0
ファイル: MainViewModel.cs プロジェクト: geersch/goo.gl
        public void Shorten()
        {
            Error      = string.Empty;
            UrlFocused = false;

            _urlShortener.Shorten(Url, UrlShortenCallback);
        }
コード例 #4
0
        public IActionResult Urls(int postId)
        {
            PostModel post;

            try
            {
                post = _blogRepository.Get(postId);
            }
            catch (EntityNotFoundException)
            {
                // Throw a 404 if the post doesn't exist
                return(NotFound());
            }

            return(new ObjectResult(new PostUrlsModel
            {
                Url = Url.BlogPostAbsolute(post),
                ShortUrl = Url.Action("Blog", "ShortUrl", new { alias = _urlShortener.Shorten(post) }, Request.Scheme),
            }));
        }
コード例 #5
0
        public virtual ActionResult Urls(int postId)
        {
            PostModel post;

            try
            {
                post = _blogRepository.Get(postId);
            }
            catch (EntityNotFoundException)
            {
                // Throw a 404 if the post doesn't exist
                return(HttpNotFound(string.Format("Blog post #{0} not found.", postId)));
            }

            return(Json(new
            {
                Url = Url.BlogPostAbsolute(post),
                ShortUrl = Url.ActionAbsolute(MVC.Blog.ShortUrl(_urlShortener.Shorten(post)))
            }, JsonRequestBehavior.AllowGet));
        }
コード例 #6
0
 /// <summary>
 /// Gets the short URL for this blog post
 /// </summary>
 /// <param name="post">Blog post</param>
 /// <returns>The short URL</returns>
 private string ShortUrl(PostModel post)
 {
     return(Url.Action("Blog", "ShortUrl", new { alias = _urlShortener.Shorten(post) }, Request.Scheme));
 }
コード例 #7
0
ファイル: FeedController.cs プロジェクト: guichengwu/Website
 /// <summary>
 /// Gets the short URL for this blog post
 /// </summary>
 /// <param name="post">Blog post</param>
 /// <returns>The short URL</returns>
 private string ShortUrl(PostModel post)
 {
     return(Url.Action(MVC.Blog.ShortUrl(_urlShortener.Shorten(post)), "http"));
 }