Example #1
0
        public ActionResult Details(string postSlug)
        {
            Post post = CacheHelper.FromCacheOrExecute(db, () => db.GetCompletePost(postSlug, HttpContext), "FujiyBlog.Core.Extensions.QueryableExtensions.GetCompletePost(" + postSlug + ") as " + User.Identity.Name);

            if (post == null)
            {
                return(NotFound());
            }

            ViewBag.Title       = post.Title;
            ViewBag.Keywords    = string.Join(",", post.PostTags.Select(x => x.Tag.Name).Concat(post.PostCategories.Select(x => x.Category.Name)));
            ViewBag.Description = post.Description;

            Post previousPost = CacheHelper.FromCacheOrExecute(db, () => db.Posts.GetPreviousPost(post, HttpContext), "FujiyBlog.Core.Extensions.QueryableExtensions.GetPreviousPost(" + post.Id + ") as " + User.Identity.Name);
            Post nextPost     = CacheHelper.FromCacheOrExecute(db, () => db.Posts.GetNextPost(post, HttpContext), "FujiyBlog.Core.Extensions.QueryableExtensions.GetNextPost(" + post.Id + ") as " + User.Identity.Name);

            PostSummary postDetails = new PostSummary
            {
                Post          = post,
                ShowFullPost  = true,
                CommentsTotal = post.Comments.Count,
                PreviousPost  = previousPost,
                NextPost      = nextPost,
            };

            return(View("Details", postDetails));
        }
        public IActionResult Index()
        {
            var blogPosts = _blogDataStore.GetAllPosts().Where(p => !p.IsDeleted && p.IsPublic).ToList();

            var postSummaries = new List <PostSummary>();

            if (!blogPosts.Any())
            {
                return(View(postSummaries));
            }

            foreach (var post in blogPosts)
            {
                var postModel = new PostSummary
                {
                    PubDate        = post.PubDate,
                    Description    = post.Description,
                    OutputStrategy = new MarkdigParser(),
                    Title          = post.Title,
                    Url            = post.Url
                };

                postSummaries.Add(postModel);
            }

            return(View(postSummaries));
        }
        public void MapCommonConditionSuccessTest()
        {
            var postSummary       = new PostSummary(2, "My test title");
            var postSummaryMapper = new PostSummaryMapper();

            Entities.PostSummary result = postSummaryMapper.Map(postSummary);

            Assert.AreEqual(2, result.Id);
            Assert.AreEqual("My test title", result.Title);
        }
Example #4
0
        public void MapDbPostDetailsTest()
        {
            var dbPost = new PostSummary
            {
                Title = "title",
                Id    = 1
            };
            var mapper = new PostSummaryMapper();
            var result = mapper.Map(dbPost);

            Assert.AreEqual(result.Id, 1);
            Assert.AreEqual(result.Title, "title");
        }
Example #5
0
        public void Apply(OpenApiOperation operation, OperationFilterContext context)
        {
            if (!(context.ApiDescription.ActionDescriptor is ControllerActionDescriptor controllerActionDescriptor))
            {
                return;
            }
            var actionName   = controllerActionDescriptor.ActionName;
            var resourceName = controllerActionDescriptor.ControllerName;

            switch (actionName)
            {
            case { } name when name.Contains("GetBy"):
                GetBySummary.Apply(ref operation, resourceName, actionName);

                break;

            case "Get" when operation.Parameters.Count == 2:
                GetAllSummary.Apply(ref operation, resourceName);
                break;

            case "Get" when controllerActionDescriptor.Parameters.Count == 1:
                GetSummary.Apply(ref operation, resourceName);
                break;

            case "Post":
                PostSummary.Apply(ref operation, resourceName);
                break;

            case "Put":
                PutSummary.Apply(ref operation, resourceName);
                break;

            case "Delete":
                DeleteSummary.Apply(ref operation, resourceName);
                break;

            case "GetTrash":
                GetTrashSummary.Apply(ref operation, resourceName);
                break;
            }
            operation.Responses["403"] = new OpenApiResponse
            {
                Description = "If administrator has blocked access to the requested action."
            };
            operation.Responses["401"] = new OpenApiResponse
            {
                Description = "If user is not registered or logged in"
            };
        }
Example #6
0
        public async Task <IEnumerable <IPostSummary> > GetPostSummaries()
        {
            var postFullPaths = _postPathRepository.GetAllPostFullPaths();

            var postSummaries = new List <IPostSummary>();

            foreach (var postFullPath in postFullPaths)
            {
                var content = await File.ReadAllTextAsync(postFullPath);

                var postMetadata = _postParserService.GetPostMetadata(content);
                var relativePath = _postPathRepository.GetPostRelativePath(postFullPath);
                var postSummary  = new PostSummary(postMetadata, relativePath);
                postSummaries.Add(postSummary);
            }

            return(postSummaries.OrderBy(x => x.PublishedOn).ToList());
        }
Example #7
0
        private string WriteHead(PostSummary post)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("<!doctype html>");
            sb.AppendLine("<html lang=\"en\">");
            sb.AppendLine("<head>");
            sb.AppendLine("<meta charset=\"utf-8\">");
            sb.AppendLine(string.Format("<title>{0}</title>", post.Title));
            sb.AppendLine(string.Format("<link rel=\"canonical\" href=\"{0}/{1}/{2}.html\">", _domain, _staticPageHtmlPath, post.Link));
            sb.AppendLine("<meta name=\"viewport\" content=\"width=device-width, initial-scale = 1\">");
            sb.AppendLine("<meta http-equiv=\"Content-Language\"content=\"en\">");
            sb.AppendLine(string.Format("<meta name=\"description\" content=\"{0}\">", post.Snippet));
            sb.AppendLine("<meta property=\"og:locale\" content=\"en_US\">");
            sb.AppendLine("<meta property=\"og:type\" content=\"article\">");
            sb.AppendLine(string.Format("<meta property=\"og:title\" content=\"{0}\">", post.Title));
            sb.AppendLine(string.Format("<meta property=\"og:description\" content=\"{0}\">", post.Snippet));
            sb.AppendLine(string.Format("<meta property=\"og:url\" content=\"{0}/{1}/{2}.html\">", _domain, _staticPageHtmlPath, post.Link));
            sb.AppendLine("<meta property=\"og:site_name\" content=\"Grenitaus Consulting, LLC\">");

            foreach (var tag in post.Tags)
            {
                sb.AppendLine(string.Format("<meta name=\"article:tag\" content=\"{0}\">", tag.Name));
            }

            foreach (var category in post.Categories)
            {
                sb.AppendLine(string.Format("<meta name=\"article:section\" content=\"{0}\">", category.Name));
            }

            sb.AppendLine(string.Format("<meta property=\"og:image\" content=\"{0}/{1}\">", _domain, post.Images[0].Url));
            sb.AppendLine("<meta name=\"twitter:card\" content=\"summary\">");
            sb.AppendLine(string.Format("<meta name=\"twitter:description\" content=\"{0}\">", post.Snippet));
            sb.AppendLine(string.Format("<meta name=\"twitter:title\" content=\"{0}\">", post.Title));

            sb.AppendLine(WriteStyles());
            sb.AppendLine(WriteScripts());

            sb.AppendLine("</head>");

            return(sb.ToString());
        }
Example #8
0
        private string WritePost(PostSummary post, PostHtml postHtml)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("<div class=\"container\">"); //container
            sb.AppendLine("<div class=\"row\">");
            sb.AppendLine("<div class=\"col-md-12\">"); //in the slimmed down version, this is 8
            sb.AppendLine(string.Format("<h1 class=\"page-header\">{0}</h1>", post.Title));
            sb.AppendLine("<div>");
            sb.AppendLine(string.Format("<p class=\"lead\">by <a href=\"{0}/about\">{1}</a></p>", _domain, post.Author));
            sb.AppendLine(string.Format("<p><span class=\"glyphicon glyphicon-time\"></span> {0}</p>", post.PostDate.ToString("MM/dd/yyyy")));
            sb.AppendLine("<div>");

            sb.Append("<small>Posted in </small><span>");
            for (int i = 0; i < post.Categories.Count(); i++)
            {
                if (post.Categories.Count() == 1 || i + 1 == post.Categories.Count())
                {
                    sb.AppendLine(string.Format("<a href=\"{0}/category/{1}\">{1}</a>", _domain, post.Categories[i].Name));
                }
                else
                {
                    sb.AppendLine(string.Format("<a href=\"{0}/category/{1}\">{1}, </a>", _domain, post.Categories[i].Name));
                }
            }
            sb.AppendLine("</span>");

            sb.Append("<small>Tagged </small><span>");
            for (int i = 0; i < post.Tags.Count(); i++)
            {
                if (post.Tags.Count() == 1 || i + 1 == post.Tags.Count())
                {
                    sb.AppendLine(string.Format("<a href=\"{0}/tag/{1}\">{1}</a>", _domain, post.Tags[i].Name));
                }
                else
                {
                    sb.AppendLine(string.Format("<a href=\"{0}/tag/{1}\">{1}, </a>", _domain, post.Tags[i].Name));
                }
            }
            sb.AppendLine("</span>");

            sb.AppendLine("</div>");

            //post
            sb.AppendLine("<hr>");
            sb.AppendLine(string.Format("<p>{0}</p>", postHtml.Hmtl));
            sb.AppendLine("</div>");
            sb.AppendLine("</div>");
            sb.AppendLine("</div>");
            sb.AppendLine("<br />");

            //share buttons
            sb.AppendLine("<div class=\"row\">");
            sb.AppendLine("<span>");
            sb.AppendLine(string.Format("<a style=\"text-decoration:none;\" href=\"mailto:?Subject={0}&amp;Body=I%20saw%20this%20and%20thought%20of%20you!%20 {1}.html\"><img src=\"assets/images/email.png\" alt=\"Email\" width=\"48\" height=\"48\"/></a>", post.Title, post.Link));
            sb.AppendLine(string.Format("<a style=\"text-decoration:none;\" href=\"http://www.linkedin.com/shareArticle?mini=true&amp;url={0}/{1}/{2}.html\" target=\"_blank\"><img src=\"assets/images/linkedin.png\" alt=\"LinkedIn\" width=\"48\" height=\"48\" /></a>", _domain, _staticPageHtmlPath, post.Link));
            sb.AppendLine(string.Format("<a style=\"text-decoration:none;\" href=\"https://plus.google.com/share?url={0}/{1}/{2}.html\" target=\"_blank\"><img src=\"assets/images/google.png\" alt=\"Google\" width=\"48\" height=\"48\" /></a>", _domain, _staticPageHtmlPath, post.Link));
            sb.AppendLine(string.Format("<a href=\"http://www.facebook.com/sharer.php?u={0}/{1}/{2}.html\" target=\"_blank\"><img src=\"assets/images/facebook.png\" alt=\"Facebook\" width=\"48\" height=\"48\" /></a>", _domain, _staticPageHtmlPath, post.Link));
            sb.AppendLine("<a style=\"text-decoration:none;\" href=\"javascript:void((function()%7Bvar%20e=document.createElement('script');e.setAttribute('type','text/javascript');e.setAttribute('charset','UTF-8');e.setAttribute('src','http://assets.pinterest.com/js/pinmarklet.js?r='+Math.random()*99999999);document.body.appendChild(e)%7D)());\"><img src=\"assets/images/pinterest.png\" alt=\"Pinterest\" width=\"48\" height=\"48\" /></a>");
            sb.AppendLine(string.Format("<a style=\"text-decoration:none;\" href=\"http://reddit.com/submit?url={0}/{1}/{2}.html&amp;title={3}\" target=\"_blank\"><img src=\"assets/images/reddit.png\" alt=\"Reddit\" width=\"48\" height=\"48\" /></a>", _domain, _staticPageHtmlPath, post.Link, post.Title));
            sb.AppendLine(string.Format("<a style=\"text-decoration:none;\" href=\"http://www.tumblr.com/share/link?url={0}/{1}/{2}.html&amp;title={3}\" target=\"_blank\"><img src=\"assets/images/tumblr.png\" alt=\"Tumblr\" width=\"48\" height=\"48\" /></a>", _domain, _staticPageHtmlPath, post.Link, post.Title));
            sb.AppendLine(string.Format("<a style=\"text-decoration:none;\" href=\"https://twitter.com/share?url={0}/{1}/{2}.html&amp;text={3}&amp;hashtags=grenitausconsulting\" target=\"_blank\"><img src=\"assets/images/twitter.png\" alt=\"Twitter\" width=\"48\" height=\"48\" /></a>", _domain, _staticPageHtmlPath, post.Link, post.Title));
            sb.AppendLine("</span>");
            sb.AppendLine("</div>");

            //also on
            PagedResponse response = _pagingService.GetAlsoOn(new PagedCriteria()
            {
                IsActive = true, Posts = BlogContextManager.PostSummaries, SearchCriteriaInt = post.Id
            });

            if (response.Total > 0)
            {
                sb.AppendLine("<hr>");
                sb.AppendLine("<div class=\"row\"><h4> Also on Blog.Michaeldeongreen.com...</h4></div>");
                sb.AppendLine("<br />");
                sb.AppendLine("<div class=\"row\">");
                foreach (var p in response.Posts)
                {
                    sb.AppendLine("<div class=\"col-md-6\">");
                    sb.AppendLine(string.Format("<h4><a href=\"{0}/post/{1}\">{2}</a></h4>", _domain, p.Link, p.Title));
                    sb.AppendLine(string.Format("by <a href=\"{0}/about\">{1}</a>", _domain, p.Author));
                    sb.AppendLine(string.Format("<p><span class=\"glyphicon glyphicon-time\"></span> {0}</p>", p.PostDate.ToString("MM/dd/yyyy")));
                    sb.AppendLine(string.Format("<p>{0}</p>", p.Snippet));
                    sb.AppendLine("</div>");
                }
                sb.AppendLine("</div>");
            }

            sb.AppendLine("</div>"); //container

            return(sb.ToString());
        }