public BlogPostDetailModel GetPostBySlug(string slug, bool pub = false) { var vm = new BlogPostDetailModel(); vm.BlogPost = _db.BlogPosts.SingleIncluded(p => p.Slug == slug).Result; if (vm.BlogPost == null) { return(null); } vm.Profile = vm.BlogPost.Profile != null ? vm.BlogPost.Profile : _db.Profiles.Single(p => p.Id == vm.BlogPost.ProfileId); if (string.IsNullOrEmpty(vm.BlogPost.Image)) { vm.BlogPost.Image = BlogSettings.Cover; if (!string.IsNullOrEmpty(BlogSettings.PostCover)) { vm.BlogPost.Image = BlogSettings.PostCover; } if (!string.IsNullOrEmpty(vm.Profile.Image)) { vm.BlogPost.Image = vm.Profile.Image; } } vm.BlogCategories = new List <SelectListItem>(); if (vm.BlogPost.PostCategories != null && vm.BlogPost.PostCategories.Count > 0) { foreach (var pc in vm.BlogPost.PostCategories) { var cat = _db.Categories.Single(c => c.Id == pc.CategoryId); vm.BlogCategories.Add(new SelectListItem { Value = cat.Slug, Text = cat.Title }); } } vm.CustomFields = GetCustom(vm.Profile.Id); if (pub) { // sanitize the post so that any potentially private information is not contained vm.BlogPost.Profile.AuthorEmail = ""; vm.BlogPost.Profile.IdentityName = ""; vm.BlogPost.Profile.IsAdmin = false; // clear variables which will cause looping issues during serialization vm.BlogPost.Profile.BlogPosts = null; vm.BlogPost.Profile.Assets = null; } return(vm); }
public async Task <IActionResult> SinglePublication(string slug) { var vm = new BlogPostDetailModel(); vm.BlogPost = await _db.BlogPosts.SingleIncluded(p => p.Slug == slug && p.Published > DateTime.MinValue); if (vm.BlogPost == null) { return(View(_theme + "Error.cshtml", 404)); } vm.Profile = _db.Profiles.Single(b => b.Id == vm.BlogPost.ProfileId); if (string.IsNullOrEmpty(vm.BlogPost.Image)) { vm.BlogPost.Image = ApplicationSettings.ProfileImage; if (!string.IsNullOrEmpty(ApplicationSettings.PostImage)) { vm.BlogPost.Image = ApplicationSettings.PostImage; } if (!string.IsNullOrEmpty(vm.Profile.Image)) { vm.BlogPost.Image = vm.Profile.Image; } } vm.BlogCategories = new List <SelectListItem>(); if (vm.BlogPost.PostCategories != null && vm.BlogPost.PostCategories.Count > 0) { foreach (var pc in vm.BlogPost.PostCategories) { var cat = _db.Categories.Single(c => c.Id == pc.CategoryId); vm.BlogCategories.Add(new SelectListItem { Value = cat.Slug, Text = cat.Title }); } } vm.CustomFields = _custom.GetProfileCustomFields(vm.Profile).Result; return(View("~/Views/Blogifier/Blog/" + vm.Profile.BlogTheme + "/Single.cshtml", vm)); }