예제 #1
0
        // GET: BlogPosts

        public ActionResult Index(int?page, string searchString)
        {
            int pageSize   = 4; // display three blog posts at a time on this page
            int pageNumber = (page ?? 1);

            var model     = new BlogIndexViewModel();
            var postQuery = db.BlogPosts.OrderBy(p => p.Created).AsQueryable();

            if (!string.IsNullOrWhiteSpace(searchString))
            {
                postQuery = postQuery
                            .Where(p => p.Title.Contains(searchString) ||
                                   p.Body.Contains(searchString) ||
                                   p.Slug.Contains(searchString) ||
                                   p.Comments.Any(t => t.Body.Contains(searchString))
                                   ).AsQueryable();
            }


            model.AllPosts    = postQuery.ToPagedList(pageNumber, pageSize);
            model.RecentPosts = db.BlogPosts.OrderByDescending(p => p.Created).Take(5).ToList();

            ViewBag.searchString = searchString;
            return(View(model));
        }
예제 #2
0
        public ViewResult Index(int page = 1)
        {
            page = page < 1 ? 1 : page;
            AlexAndNikkiDBEntities dbContext = new AlexAndNikkiDBEntities();

            var blogPostsToShow = dbContext.BlogPosts;

            var pagingInfo = new PagingInfo
            {
                CurrentPage  = page,
                ItemsPerPage = 5,
                TotalItems   = blogPostsToShow.Count()
            };

            var viewModel = new BlogIndexViewModel
            {
                BlogPosts = blogPostsToShow
                            .OrderByDescending(x => x.Date)
                            .Skip((page - 1) * 5)
                            .Take(5)
                            .ToList(),
                PagingInfo = pagingInfo
            };

            return(View("Blog", viewModel));
        }
예제 #3
0
        public ActionResult Index()
        {
            BlogIndexViewModel blogIndexViewModel = new BlogIndexViewModel {
                Posts = _repo.GetThreeMostRecentPosts()
            };

            return(View(blogIndexViewModel));
        }
예제 #4
0
        public ActionResult Index()
        {
            //return this.View();
            BlogIndexViewModel result = this._blogPostOperations.GetBlogIndexViewModel();

            ViewBag.Title = "Blog";
            return(this.View(result));
        }
예제 #5
0
        public ActionResult Index()
        {
            var model = new BlogIndexViewModel()
            {
                Posts = _repo.GetApprovedPosts()
            };

            return(View(model));
        }
예제 #6
0
        public ActionResult Index()
        {
            //return this.View();
            int maxRows = 11;
            BlogIndexViewModel result = this._blogPostOperations.GetBlogIndexViewModelPagination(1, maxRows);

            ViewBag.Title   = "Blog";
            Session["Page"] = 1;
            return(this.View(result));
        }
예제 #7
0
        public ActionResult IndexPaging()
        {
            int maxRows = 10;
            int x       = (int)Session["Page"] + 1;

            Session["Page"] = x;
            BlogIndexViewModel result = this._blogPostOperations.GetBlogIndexViewModelPagination(x, maxRows);

            return(PartialView("~/Views/BlogPost/_IndexItemsPartial.cshtml", result.BlogPosts));
        }
예제 #8
0
        public ActionResult Blogs()
        {
            BlogIndexViewModel model = new BlogIndexViewModel();

            model.IndexBlogs   = repository.Blogs.OrderByDescending(b => b.Id).Take(4).ToList();
            model.PopularBlogs = repository.Blogs.Where(b => b.Popularity > 3).Take(4).ToList();
            model.RecentBlogs  = repository.Blogs.OrderByDescending(b => b.Id).Take(9).Reverse().ToList();
            model.RecentBlogs  = model.RecentBlogs.Take(5).ToList();
            return(PartialView("~/Views/Blog/_blogs.cshtml", model));
        }
예제 #9
0
        public IActionResult Index(BlogIndexViewModel blogIndexViewModel)
        {
            blogIndexViewModel.AllArticles = this.BlogService.GetAllArticles();

            foreach (var article in blogIndexViewModel.AllArticles)
            {
                article.Comments = this.CommentService.GetArticleComments(article.Id);
            }

            return(this.View(blogIndexViewModel));
        }
예제 #10
0
        public IActionResult Index(BlogPostsRequestViewModel request)
        {
            var blogPosts = _blogPostRepository.ToPagedListOfPublishedBlogPosts(request);

            var model = new BlogIndexViewModel()
            {
                BlogPosts = blogPosts
            };

            return(View(model));
        }
예제 #11
0
        [HttpGet] // displays blog landing page
        public IActionResult Index()
        {
            var request   = new ListRecentBlogPostsRequest();
            var response  = _listRecentBlogPostsInteractor.ListRecentBlogPosts(request);
            var viewmodel = new BlogIndexViewModel();

            if (response.RequestSuccessful)
            {
                viewmodel.RecentPosts = MapListOfBlogPostToListOfDTOModel(response.ListOfRecentPosts);
            }
            return(View(viewmodel));
        }
예제 #12
0
        // GET: Blog
        public async Task <IActionResult> Index()
        {
            /*
             * Continuing with view models and we setup our blog index view model
             */
            BlogIndexViewModel viewModel = new BlogIndexViewModel()
            {
                Posts = await _DB.Posts.ToListAsync()
            };

            return(View(viewModel));
        }
예제 #13
0
        private BlogIndexViewModel getViewModelFrom(List <CMS.Core.Entity.Blog> blogs)
        {
            BlogIndexViewModel vm = new BlogIndexViewModel();

            vm.blog_details = new List <BlogDetailModel>();
            foreach (var blog in blogs)
            {
                var Blogs = _mapper.Map <BlogDetailModel>(blog);
                vm.blog_details.Add(Blogs);
            }

            return(vm);
        }
예제 #14
0
        public IActionResult Index()
        {
            var viewModel = new BlogIndexViewModel();

            viewModel.AllArticles = this.BlogService.GetAllArticles();

            foreach (var article in viewModel.AllArticles)
            {
                article.Comments = this.CommentService.GetArticleComments(article.Id);
            }

            viewModel.Cloudinary = this.cloudinaryService.GetCloudinaryInstance();

            return(this.View(viewModel));
        }
예제 #15
0
        public IActionResult Index(int page = 1, int pageSize = 3)
        {
            BlogIndexViewModel blogIndex = new BlogIndexViewModel()
            {
            };

            blogIndex.ResultPagging.Items     = _blogService.GetAllPaggingByActive(page, pageSize, out int totalRows);
            blogIndex.ResultPagging.PageIndex = page;
            blogIndex.ResultPagging.PageSize  = pageSize;
            blogIndex.ResultPagging.TotalRows = totalRows;
            blogIndex.DomainApi      = _config["DomainApi:Domain"];
            blogIndex.Tags           = _blogService.GetTagBlogTop(15);
            blogIndex.Advertistments = _advertistmentService.GetbyPageAndPosition(PageName.Orther, PositionName.Default);
            return(View(blogIndex));
        }
예제 #16
0
        public async Task <IActionResult> Blog(int page = 1, int perPage = BlogPerPage)
        {
            var pagesCount = await this.blogService.GetPagesCount(perPage);

            var viewModel = new BlogIndexViewModel
            {
                BlogViewModels = await this.blogService.TakeAllBlogs <BlogViewModel>(page, perPage),

                // Display 3 random blogs to the user.
                SideBlogViewModels = await this.blogService.TakeRandomBlogs <BlogViewModel>(TakeBlogs),
                CurrentPage        = page,
                PagesCount         = pagesCount,
            };

            return(this.View(viewModel));
        }
예제 #17
0
        public async Task <ActionResult> Index(int page = 1, int pageSize = 2)
        {
            //return this.View();
            BlogIndexViewModel result = await this._blogPostOperations.GetBlogIndexViewModelAsync(page, pageSize);

            foreach (var item in result.BlogPosts.Results)
            {
                if (!authers.ContainsKey(item.AuthorID))
                {
                    item.Author.AutherLikes = _blogPostOperations.CountPostsLikesPerAuther(item.AuthorID);
                    authers.Add(item.AuthorID, item.Author.AutherLikes.ToString());
                }
                else
                {
                    var count = authers.FirstOrDefault(x => x.Key == item.AuthorID).Value;
                    item.Author.AutherLikes = Convert.ToInt32(count);
                }
            }
            ViewBag.Title = "Blog";
            return(this.View(result));
        }
예제 #18
0
        public ActionResult Index(int categoryID = 0, int p = 0)
        {
            var viewModel = new BlogIndexViewModel {
                CategoryID = categoryID, PageNum = p
            };

            var query =
                db.trnblogs
                .GroupJoin(db.tblmembers, a => a.MemberID, b => b.ID, (a, b) => new { Blog = a, Member = b.FirstOrDefault(), })
                .Where(a => !a.Blog.CancelDT.HasValue && a.Blog.Language == lang &&
                       (a.Blog.CategoryID == categoryID || categoryID == 0) && a.Blog.Active)
                .OrderByDescending(a => a.Blog.ID);

            var pageSize  = Settings.Default.MaxListPerPage;
            var rowsCount = query.Count();

            viewModel.TotalPage = rowsCount / pageSize;
            if (rowsCount % pageSize > 0)
            {
                viewModel.TotalPage++;
            }

            //If page number should be > 0 else set to first page
            if (rowsCount <= pageSize || viewModel.PageNum <= 0)
            {
                viewModel.PageNum = 1;
            }

            //Calculate nunber of rows to skip on pagesize
            int excludedRows = (viewModel.PageNum - 1) * pageSize;

            viewModel.Blogs =
                query
                .Select(a => new BlogDetails
            {
                ID                 = a.Blog.ID,
                CategoryID         = a.Blog.CategoryID,
                Title              = a.Blog.Title,
                Body               = a.Blog.Body,
                LastEditedDate     = a.Blog.UpdateDT.HasValue ? a.Blog.UpdateDT.Value : a.Blog.CreateDT,
                CreatedBy          = a.Member == null ? "EMMA STONE" : a.Member.PICName,
                TotalComments      = db.lnkblogcomments.Where(b => b.BlogID == a.Blog.ID && !b.CancelDT.HasValue).Count(),
                ThumbnailImagePath = a.Blog.ThumbnailImagePath
            })
                .Skip(excludedRows)
                .Take(pageSize)
                .ToList();

            viewModel.PopularBlogs =
                db.trnblogs
                .GroupJoin(db.tblmembers, a => a.MemberID, b => b.ID, (a, b) => new { Blog = a, Member = b })
                .GroupJoin(db.lnkblogcomments, a => a.Blog.ID, b => b.BlogID, (a, b) => new
            {
                Blog         = a.Blog,
                Member       = a.Member.FirstOrDefault(),
                BlogComments = b
            })
                .Where(a => !a.Blog.CancelDT.HasValue && a.Blog.Language == lang && a.Blog.Active)
                .Select(a => new PopularBlog
            {
                ID                 = a.Blog.ID,
                Author             = a.Member == null ? "EMMA STONE" : a.Member.PICName,
                CreateDT           = a.Blog.CreateDT,
                NoOfComments       = a.BlogComments.Count(),
                Title              = a.Blog.Title,
                ThumbnailImagePath = a.Blog.ThumbnailImagePath
            })
                .OrderByDescending(a => a.NoOfComments)
                .Take(5)
                .ToList();

            viewModel.LatestBlogComments =
                db.lnkblogcomments
                .GroupJoin(db.tblmembers, a => a.MemberID, b => b.ID, (a, b) => new { BlogComment = a, Member = b })
                .GroupJoin(db.trnblogs, a => a.BlogComment.BlogID, b => b.ID, (a, b) => new
            {
                BlogComment = a.BlogComment,
                Member      = a.Member.FirstOrDefault(),
                Blog        = b.FirstOrDefault()
            })
                .Where(a => !a.Blog.CancelDT.HasValue && a.Blog.Language == lang && a.Blog.Active)
                .Select(a => new LatestBlogComment
            {
                ID       = a.Blog == null ? 0: a.Blog.ID,
                Author   = a.Member == null ? "EMMA STONE" : a.Member.PICName,
                CreateDT = a.BlogComment.CreateDT,
                Comment  = a.BlogComment.Comments,
                Title    = a.Blog.Title
            })
                .OrderByDescending(a => a.CreateDT)
                .Take(5)
                .ToList();

            viewModel.Categories = db.refcategories
                                   .GroupJoin(db.trnblogs, a => a.ID, b => b.CategoryID, (a, b) => new { Category = a, Blogs = b })
                                   .Where(a => a.Category.Active && a.Category.Language == lang)
                                   .OrderBy(a => a.Category.Name)
                                   .Select(a => new BlogCategory()
            {
                ID    = a.Category.ID,
                Name  = a.Category.Name,
                Count = a.Blogs.Where(bb => bb.Active).Count()
            }).ToList();

            return(View(viewModel));
        }