public ActionResult Category(string category, int?page) { int skip = (page.GetValueOrDefault(1) - 1) * settings.PostsPerPage; PostIndex model = new PostIndex { CurrentPage = page.GetValueOrDefault(1), RecentPosts = GetRecentPostsCache(skip, settings.PostsPerPage, category: category), TotalPages = (int)Math.Ceiling(GetTotalCache(category: category) / (double)settings.PostsPerPage), }; if (page > model.TotalPages || !model.RecentPosts.Any()) { return(NotFound()); } ViewBag.Title = category; if (page.HasValue) { ViewBag.Title += " - Page " + page.Value; } ViewBag.Description = ViewBag.Title; return(View("Index", model)); }
public ActionResult ArchiveDate(int year, int month, int?page) { int skip = (page.GetValueOrDefault(1) - 1) * settings.PostsPerPage; DateTime startDate = new DateTime(year, month, 1); DateTime endDate = startDate.AddMonths(1); PostIndex model = new PostIndex { CurrentPage = page.GetValueOrDefault(1), RecentPosts = GetRecentPostsCache(skip, settings.PostsPerPage, startDate: startDate, endDate: endDate), TotalPages = (int)Math.Ceiling(GetTotalCache(startDate: startDate, endDate: endDate) / (double)settings.PostsPerPage), }; if (page > model.TotalPages) { return(NotFound()); } ViewBag.Title = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(month) + " - " + year; if (page.HasValue) { ViewBag.Title += " - Page " + page.Value; } ViewBag.Description = ViewBag.Title; return(View("Index", model)); }
public ActionResult Index(int?page) { int skip = (page.GetValueOrDefault(1) - 1) * settings.PostsPerPage; PostIndex model = new PostIndex { CurrentPage = page.GetValueOrDefault(1), RecentPosts = GetRecentPostsCache(skip, settings.PostsPerPage, null, null, null, null, null), TotalPages = (int)Math.Ceiling(GetTotalCache(null, null, null, null, null) / (double)settings.PostsPerPage), }; if (page > model.TotalPages) { return(NotFound()); } ViewBag.Title = settings.BlogName + " - " + settings.BlogDescription; ViewBag.Description = settings.BlogDescription; if (page.HasValue) { ViewBag.Title += " - Page " + page.Value; ViewBag.Description += " - Page " + page.Value; } return(View(model)); }
public ActionResult Tag(string tag, int?page) { int skip = (page.GetValueOrDefault(1) - 1) * settings.PostsPerPage; PostIndex model = new PostIndex { CurrentPage = page.GetValueOrDefault(1), RecentPosts = postRepository.GetRecentPosts(skip, settings.PostsPerPage, tag), TotalPages = (int)Math.Ceiling(postRepository.GetTotal(tag) / (double)settings.PostsPerPage), }; if (page > model.TotalPages || !model.RecentPosts.Any()) { return(NotFound()); } ViewBag.Title = "All posts tagged '" + tag + "'"; if (page.HasValue) { ViewBag.Title += " - Page " + page.Value; } ViewBag.Description = ViewBag.Title; return(View("Index", model)); }
public ActionResult Author(string author, int?page) { int skip = (page.GetValueOrDefault(1) - 1) * settings.PostsPerPage; PostIndex model = new PostIndex { CurrentPage = page.GetValueOrDefault(1), RecentPosts = GetRecentPostsCache(skip, settings.PostsPerPage, authorUserName: author), TotalPages = (int)Math.Ceiling(GetTotalCache(authorUserName: author) / (double)settings.PostsPerPage), }; var authorUser = db.Users.SingleOrDefault(x => x.UserName == author && x.Enabled == true); if (page > model.TotalPages || authorUser == null) { return(NotFound()); } ViewBag.Title = "All posts by '" + (authorUser.DisplayName ?? authorUser.UserName) + "'"; ViewBag.Description = authorUser.About; if (page.HasValue) { ViewBag.Title += " - Page " + page.Value; ViewBag.Description += " - Page " + page.Value; } return(View("Index", model)); }
public ActionResult Index(int?page) { int skip = (page.GetValueOrDefault(1) - 1) * settings.PostsPerPage; PostIndex model = new PostIndex { CurrentPage = page.GetValueOrDefault(1), RecentPosts = CacheHelper.FromCacheOrExecute(db, () => postRepository.GetRecentPosts(skip, settings.PostsPerPage, null, null, null, null, null), cacheItemPolicy: new MemoryCacheEntryOptions { AbsoluteExpiration = DateTimeOffset.Now.AddMinutes(5) }, condition: !User.Identity.IsAuthenticated), TotalPages = (int)Math.Ceiling(CacheHelper.FromCacheOrExecute(db, () => postRepository.GetTotal(null, null, null, null, null), cacheItemPolicy: new MemoryCacheEntryOptions { AbsoluteExpiration = DateTimeOffset.Now.AddHours(1) }, condition: !User.Identity.IsAuthenticated) / (double)settings.PostsPerPage), }; if (page > model.TotalPages) { return(NotFound()); } ViewBag.Title = settings.BlogName + " - " + settings.BlogDescription; ViewBag.Description = settings.BlogDescription; if (page.HasValue) { ViewBag.Title += " - Page " + page.Value; ViewBag.Description += " - Page " + page.Value; } return(View(model)); }
public async Task <IActionResult> Index() { Home_Index data = new Home_Index(); PostIndex postIndex = new PostIndex(); int count_canban = 0; int count_canmua = 0; int count_canthue = 0; int count_canchothue = 0; data.lst3HotPosts = postIndex.get3HotPosts(); data.lst6PopularPosts = postIndex.get6PopularPosts(); count_canban = postIndex.getCount(1); count_canmua = postIndex.getCount(3); count_canthue = postIndex.getCount(4); count_canchothue = postIndex.getCount(2); ViewBag.canban = count_canban; ViewBag.canmua = count_canmua; ViewBag.canthue = count_canthue; ViewBag.canchothue = count_canchothue; var user = await _userManager.GetUserAsync(User); if (user != null) { ViewBag.favoritepost = DataProvider.Ins.db.Post_Favorite.Include(p => p.ID_PostNavigation).ThenInclude(p => p.Post_Image).Include(p => p.ID_PostNavigation).ThenInclude(p => p.PostTypeNavigation).Include(p => p.ID_PostNavigation).ThenInclude(p => p.RealEstateTypeNavigation).Include(p => p.ID_UserNavigation) .Where(p => p.ID_User == user.Id).OrderByDescending(p => p.MortifiedDate).Take(5).ToList(); } return(View(data)); }
public IActionResult Index(int id) { var post = _postService.GetById(id); var replies = BuildPostReplies(post.Replies); var model = new PostIndex { Id = post.Id, Title = post.Title, AuthorId = post.User.Id, AuthorName = post.User.UserName, AuthorImageUrl = post.User.ProfileImageUrl, AuthorRating = post.User.Rating, Created = post.Created, PostContent = post.Content, Replies = replies }; return(View(model)); }
// // GET: /Post/ public ActionResult Index(int?id) { var post = ThreadedCommentsContext.Posts .Include("Board") .SingleOrDefault(p => p.PostId == id); if (post == null) { throw new Exception("No Post with id = " + id); } var comments = ThreadedCommentsContext.Comments .Where(c => c.PostId == id && c.BoardId == post.BoardId) .OrderBy(c => c.SortOrder) .Take(50) .ToList() .Select(c => new PostIndex.CommentInfo { CommentId = c.CommentId, Body = c.Body, AuthorName = c.AuthorName, AuthorEmail = c.AuthorEmail, CommentUtcDate = c.CommentUtcDate, Indent = c.Indent }) .ToList(); var viewModel = new PostIndex(); viewModel.PostId = post.PostId; viewModel.Title = post.Title; viewModel.Body = post.Body; viewModel.AuthorName = post.AuthorName; viewModel.AuthorEmail = post.AuthorEmail; viewModel.PostUtcDate = post.PostUtcDate; viewModel.Comments = comments; return(View(viewModel)); }
// // GET: /Post/ public ActionResult Index(int? id) { var post = ThreadedCommentsContext.Posts .Include("Board") .SingleOrDefault(p => p.PostId == id); if (post == null) { throw new Exception("No Post with id = " + id); } var comments = ThreadedCommentsContext.Comments .Where(c => c.PostId == id && c.BoardId == post.BoardId) .OrderBy(c => c.SortOrder) .Take(50) .ToList() .Select(c => new PostIndex.CommentInfo { CommentId = c.CommentId, Body = c.Body, AuthorName = c.AuthorName, AuthorEmail = c.AuthorEmail, CommentUtcDate = c.CommentUtcDate, Indent = c.Indent }) .ToList(); var viewModel = new PostIndex(); viewModel.PostId = post.PostId; viewModel.Title = post.Title; viewModel.Body = post.Body; viewModel.AuthorName = post.AuthorName; viewModel.AuthorEmail = post.AuthorEmail; viewModel.PostUtcDate = post.PostUtcDate; viewModel.Comments = comments; return View(viewModel); }
public async Task <IActionResult> PostDetail(int id) { //if (id == null) //{ // return NotFound(); //} //var post = await _context.Post.Include(p => p.ID_AccountNavigation).Include(p => p.PostTypeNavigation).Include(p => p.ProjectNavigation) // .Include(p => p.RealEstateTypeNavigation).Include(p => p.Post_Location).ThenInclude(lo => lo.Tinh_TPNavigation.Post_Location) // .ThenInclude(lo => lo.Quan_HuyenNavigation.Post_Location).ThenInclude(lo => lo.Phuong_XaNavigation.Post_Location) // .ThenInclude(lo => lo.Duong_PhoNavigation.Post_Location) // .Include(d => d.Post_Detail). // Include(image => image.Post_Image) // .Include(p => p.Post_Status) // .ThenInclude(pt => pt.StatusNavigation.Post_Status).Where(p => p.ID_Post == id).SingleOrDefaultAsync(); var post = _postRepository.GetPostByID(id); if (post == null) { return(NotFound()); } var user = await _context.AspNetUsers.Where(p => p.Id == post.ID_Account).SingleOrDefaultAsync(); PostIndex postIndex = new PostIndex(); int count_canban = 0; int count_canmua = 0; int count_canthue = 0; int count_canchothue = 0; count_canban = postIndex.getCount(1); count_canmua = postIndex.getCount(3); count_canthue = postIndex.getCount(4); count_canchothue = postIndex.getCount(2); ViewBag.canban = count_canban; ViewBag.canmua = count_canmua; ViewBag.canthue = count_canthue; ViewBag.canchothue = count_canchothue; if (user.IsAdmin == 1) { ViewData["image"] = _context.Admin.Where(p => p.Account_ID == user.Id).SingleOrDefault().Avatar_URL; } else { ViewData["image"] = _context.Customer.Where(p => p.Account_ID == user.Id).SingleOrDefault().Avatar_URL; } if (ViewData["image"] == null) { ViewData["image"] = "avatar_common.png"; } var userCurrent = await _userManager.GetUserAsync(User); if (userCurrent != null) { ViewBag.favoritepost = _context.Post_Favorite.Include(p => p.ID_PostNavigation).ThenInclude(p => p.Post_Image).Include(p => p.ID_PostNavigation).ThenInclude(p => p.PostTypeNavigation).Include(p => p.ID_PostNavigation).ThenInclude(p => p.RealEstateTypeNavigation).Include(p => p.ID_UserNavigation) .Where(p => p.ID_User == user.Id).OrderByDescending(p => p.MortifiedDate).Take(5).ToList(); } return(View(post)); }