Example #1
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(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)
            }));
        }
Example #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)
            }));
        }
Example #3
0
        public void Shorten()
        {
            Error      = string.Empty;
            UrlFocused = false;

            _urlShortener.Shorten(Url, UrlShortenCallback);
        }
        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),
            }));
        }
Example #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));
        }
 /// <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));
 }
Example #7
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(MVC.Blog.ShortUrl(_urlShortener.Shorten(post)), "http"));
 }