public IList<PostVideo> GetPostVideos(Post post) { var postUrls = _context.PostVideos.Where(p => p.PostId == post.Id).ToList(); List<PostVideo> videos = new List<PostVideo>(); foreach (var url in postUrls) { videos.Add(url); } return videos; }
public IList<Tag> GetPostTags(Post post) { var tagIds = _context.PostTags.Where(p => p.PostId == post.Id).Select(p => p.TagId).ToList(); List<Tag> tags = new List<Tag>(); foreach (var tagId in tagIds) { tags.Add(_context.Tags.Where(p => p.Id == tagId).FirstOrDefault()); } return tags; }
public IList<Category> GetPostCategories(Post post) { var categoryIds = _context.PostCategories.Where(p => p.PostId == post.Id).Select(p => p.CategoryId).ToList(); List<Category> categories = new List<Category>(); foreach (var catId in categoryIds) { categories.Add(_context.Categories.Where(p => p.Id == catId).FirstOrDefault()); } return categories; }
public ActionResult Comments(PostViewModel model, Post post, string sortOrder) { ViewBag.CurrentSort = sortOrder; ViewBag.DateSortParm = string.IsNullOrEmpty(sortOrder) ? "date_asc" : ""; ViewBag.BestSortParm = sortOrder == "Best" ? "best_desc" : "Best"; var postComments = _blogRepository.GetPostComments(post).OrderByDescending(d => d.DateTime).ToList(); foreach (var comment in postComments) { var likes = LikeDislikeCount("commentlike", comment.Id); var dislikes = LikeDislikeCount("commentdislike", comment.Id); comment.NetLikeCount = likes - dislikes; if (comment.Replies != null) comment.Replies.Clear(); List<CommentViewModel> replies = _blogRepository.GetParentReplies(comment); foreach (var reply in replies) { var rep = _blogRepository.GetReplyById(reply.Id); comment.Replies.Add(rep); } } switch (sortOrder) { case "date_asc": postComments = postComments.OrderBy(x => x.DateTime).ToList(); ViewBag.DateSortLink = "active"; break; case "Best": postComments = postComments.OrderByDescending(x => x.NetLikeCount).ToList(); ViewBag.BestSortLink = "active"; break; case "best_desc": postComments = postComments.OrderBy(x => x.NetLikeCount).ToList(); ViewBag.BestSortLink = "active"; break; default: postComments = postComments.OrderByDescending(x => x.DateTime).ToList(); ViewBag.DateSortLink = "active"; break; } model.UrlSeo = post.UrlSeo; model.Comments = postComments; return PartialView(model); }
public ActionResult AddNewPost(PostViewModel model) { var post = new Post { Id = model.ID, Body = model.Body, Meta = model.Meta, PostedOn = DateTime.Now, Published = true, ShortDescription = model.ShortDescription, Title = model.Title, UrlSeo = model.UrlSeo }; _blogRepository.AddNewPost(post); return RedirectToAction("EditPost", "Blog", new { slug = model.UrlSeo }); }
public IList<PostVideo> GetPostVideos(Post post) { return _blogRepository.GetPostVideos(post); }
public IList<Tag> GetPostTags(Post post) { return _blogRepository.GetPostTags(post); }
public IList<Category> GetPostCategories(Post post) { return _blogRepository.GetPostCategories(post); }
public IList<Comment> GetPostComments(Post post) { return _context.Comments.Where(p => p.PostId == post.Id).ToList(); }
public void AddNewPost(Post post) { _context.Posts.Add(post); Save(); }