Пример #1
0
 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;
 }
Пример #2
0
 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;
 }
Пример #3
0
 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;
 }
Пример #4
0
        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);
        }
Пример #5
0
 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 });
 }
Пример #6
0
 public IList<PostVideo> GetPostVideos(Post post)
 {
     return _blogRepository.GetPostVideos(post);
 }
Пример #7
0
 public IList<Tag> GetPostTags(Post post)
 {
     return _blogRepository.GetPostTags(post);
 }
Пример #8
0
 public IList<Category> GetPostCategories(Post post)
 {
     return _blogRepository.GetPostCategories(post);
 }
Пример #9
0
 public IList<Comment> GetPostComments(Post post)
 {
     return _context.Comments.Where(p => p.PostId == post.Id).ToList();
 }
Пример #10
0
 public void AddNewPost(Post post)
 {
     _context.Posts.Add(post);
     Save();
 }