// Id ye göre 1 adet post ve onun yorumlarını çek ve sayfala public PostRowVM GetPostById(string searchText, int id, int currentPage = 1) { var commentCount = _commentService.GetAllByPostId(id).Count(); var commentSize = 8; var pageCount = (commentCount / commentSize) + (commentCount % commentSize > 0 ? 1 : 0); var model = new PostRowVM(); model.CurrentPage = currentPage; model.PageCount = pageCount; model.PreviousPage = (currentPage - 1) > 0 ? currentPage - 1 : pageCount; model.NextPage = currentPage + 1 > pageCount ? 1 : currentPage + 1; var post = _postRepository.Get(x => x.Id == id); if (post != null) { (post.ViewCount) = (post.ViewCount) + 1; model.ViewCount = (post.ViewCount); model.Title = post.Title; model.postId = post.Id; model.CreateDate = post.CreateDate; model.LikeCount = _ratingRepository.GetAll(x => x.Isliked == true && x.PostId == post.Id).Count(); model.DislikeCount = _ratingRepository.GetAll(x => x.IsDisliked == true && x.PostId == post.Id).Count(); model.Comments = _commentService.GetAllByPostId(post.Id).Skip((currentPage - 1) * commentSize).Take(commentSize).ToList(); model.apiRowVM = _apiService.GetApi(searchText); } _postRepository.SaveChanges(); return(model); }
//Seçili kategoriye göre postları çekme public List <PostRowVM> GetAllByCategoryId(int selectedCategoryId) { var list = new List <PostRowVM>(); _postRepository.GetAllByCategoryId(selectedCategoryId).ToList() .ForEach(x => { var item = new PostRowVM(); item.postId = x.Id; item.Title = x.Title; item.CommentCount = _commentService.GetAllByPostId(x.Id).Count(); list.Add(item); }); return(list); }