public ActionResult Details(int id = 0) { var bd = _blogUtil.GetDetailDisplay(id); if (bd == null) { return(NotFound()); } if (IsHarmony) { bd.tag = bd.tag.Where(i => !HarmonySettings.WhitelistTags.Contains(i.TagID)); } var bannerBlogId = _dataSettings.BannerBlogIdList(); bd.Option.NoRate = (FeaturedBlogId != null && FeaturedBlogId.Contains(id)) || (bannerBlogId != null && bannerBlogId.Contains(id)) || bd.Option.NoRate; if (User.Identity.IsAuthenticated) { ViewBag.isFavorite = bd.IsFavorite; } string referrer = Request.Headers[HeaderNames.Referer]; if (referrer != null && (referrer.IndexOf("Create", StringComparison.OrdinalIgnoreCase) > 0 || referrer.IndexOf("Edit", StringComparison.OrdinalIgnoreCase) > 0)) { Response.Headers["X-XSS-Protection"] = "0"; } return(View(bd)); }
public IActionResult Details(int id) { var bd = blogUtil_.GetDetailDisplay(id); if (bd == null) { return(NotFound()); } var author = udb_.Users.SingleOrDefault(u => u.UserName == bd.blog.Author); User authorInfo = new User { UserName = bd.blog.Author, NickName = bd.blog.Author }; if (author != null) { authorInfo = Models.App.User.FromUserProfile(author, Url.Action("Show", "Avatar", new { name = authorInfo.UserName }, Request.Scheme)); } var comments = db_.Posts.Where(p => p.IdType == ItemType.Blog && p.ItemId == id) .GroupJoin(db_.BlogRatings, p => p.PostId, r => r.PostId, (p, r) => new { post = p, ratings = r }) .SelectMany(a => a.ratings.DefaultIfEmpty(), (p, r) => new { p.post, blograting = r, uc = p.post.Ratings.Count(ra => ra.Value == 1), dc = p.post.Ratings.Count(ra => ra.Value == -1), uv = User.Identity.IsAuthenticated ? p.post.Ratings.FirstOrDefault(ra => ra.Rater == User.Identity.Name) : null }) .OrderByDescending(p => p.post.Rating) .ThenByDescending(p => p.post.PostDate) .Take(5) .Select(c => new Comment { Author = c.post.Author, CommentId = c.post.PostId, Content = c.post.Content, ItemId = c.post.ItemId, UpvoteCount = c.uc, DownvoteCount = c.dc, IsUpvoted = c.uv == null ? new bool?() : c.uv.Value == 1, IsDownvoted = c.uv == null ? new bool?() : c.uv.Value == -1, CreateDate = c.post.PostDate, Type = Comment.CommentType.Blog, Rating = c.blograting == null ? new int?() : c.blograting.value }) .ToArray(); var rating = ratingUtil_.GetUsersRating(id); return(Json(GetBlogDetails(bd, authorInfo, comments, rating.Rating == null ? new int?() : rating.Rating.value))); }