public ActionResult Index(int page = 0, string authorId = null) { var authors = GetUsersByRoleName("author"); var entities = authorId != null ? _postManager.Get(x => !x.IsBlocked && x.AuthorId == authorId).Reverse() : _postManager.Get(x => !x.IsBlocked); var mostViewedData = entities.OrderByDescending(x => x.UsersReadCount).Take(MOST_VIEWED).ToList(); var mostViewed = _mapper.Map <IList <PostViewModel> >(mostViewedData); var count = entities.Count(); var data = entities.Reverse().Skip(page * PAGE_SIZE).Take(PAGE_SIZE).ToList(); var entitiesMap = _mapper.Map <IList <PostViewModel> >(data); var result = new AllPostsViewModel { Posts = entitiesMap, MostViewed = mostViewed, Authors = authors, Page = page, MaxPage = (count / PAGE_SIZE) - (count % PAGE_SIZE == 0 ? 1 : 0), AuthorId = authorId }; return(View(result)); }
public IActionResult All(int id, string search, int courseId) { id = Math.Max(1, id); var skip = (id - 1) * this.ItemsPerPage; var query = this.postsService.GetAll <PostViewModel>(); if (search != null) { query = this.postsService.SearchByTitle <PostViewModel>(search); } if (courseId != 0) { query = this.postsService.GetByCourseId <PostViewModel>(courseId); } var posts = query .Skip(skip) .Take(this.ItemsPerPage) .ToList(); foreach (var post in posts) { post.LastActive = this.commentsService.GetLastActiveCommentByPostId <LastActiveViewModel>(post.Id); if (post.LastActive == null) { LastActiveViewModel lastActive = new LastActiveViewModel { Name = post.AuthorName, }; if (post.CreatedOn > post.ModifiedOn) { lastActive.LastActive = post.CreatedOn; } else { lastActive.LastActive = post.ModifiedOn; } post.LastActive = lastActive; } } var postsCount = query.Count(); var pagesCount = (int)Math.Ceiling(postsCount / (decimal)this.ItemsPerPage); AllPostsViewModel viewModel = new AllPostsViewModel { Posts = posts.OrderByDescending(p => p.LastActive.LastActive), Courses = this.coursesService.GetAll <CourseViewModel>(), CurrentPage = id, PagesCount = pagesCount, PostsCount = postsCount, Search = search, CourseId = courseId, }; return(this.View(viewModel)); }
public IActionResult Index(int page = 1) { var viewModel = new AllPostsViewModel(); viewModel.AllPosts = this.postsService.GetPosts <PostViewModel>(PostsPerPage, (page - 1) * PostsPerPage); var postsCount = this.postsService.GetCount(); viewModel.PagesCount = (int)Math.Ceiling((double)postsCount / PostsPerPage); viewModel.CurrentPage = page; return(this.View(viewModel)); }
public IActionResult Index() { var viewModel = new AllPostsViewModel { Posts = this.postsService.GetAll <PostViewModel>(), }; if (viewModel == null) { return(this.NotFound()); } return(this.View(viewModel)); }
public ActionResult AllPosts(int page = 0) { var entities = _postManager.Get().Reverse(); var count = entities.Count(); var data = entities.Skip(page * PAGE_SIZE).Take(PAGE_SIZE).ToList(); var entitiesMap = _mapper.Map <IList <PostViewModel> >(data); var result = new AllPostsViewModel { Posts = entitiesMap, Page = page, MaxPage = (count / PAGE_SIZE) - (count % PAGE_SIZE == 0 ? 1 : 0) }; return(View(result)); }
public IActionResult PostsByTitle(string title) { var viewModel = new AllPostsViewModel { Posts = this.postsService.GetByTitle <PostViewModel>(title), PostQuery = title, }; if (viewModel == null) { return(this.NotFound()); } return(this.View(viewModel)); }
public IActionResult Index() { var posts = new List <string>(); for (int i = 0; i < 100; i++) { posts.Add($"New post {i}"); } var viewModel = new AllPostsViewModel() { Posts = posts }; return(View(viewModel)); }
public ActionResult MyPosts(int page = 0) { var userId = User.Identity.GetUserId(); var entities = _postManager.Get(x => x.AuthorId == userId).Reverse(); var count = entities.Count(); var data = entities.Skip(page * PAGE_SIZE).Take(PAGE_SIZE).ToList(); var entitiesMap = _mapper.Map <IList <PostViewModel> >(data); var user = _userService.Get(User.Identity.GetUserId()); var result = new AllPostsViewModel { Posts = entitiesMap, Page = page, MaxPage = (count / PAGE_SIZE) - (count % PAGE_SIZE == 0 ? 1 : 0), IsUserBlocked = user?.IsUserBlocked ?? false }; return(View(result)); }
public async Task <IActionResult> AllPosts(int?sortby = 1) { var vm = new AllPostsViewModel(); // Sort by Category if (sortby == 1) { GetAllPostsByCategoryViewModelQuery gvapbc = new GetAllPostsByCategoryViewModelQuery(); vm = await _qpa.ProcessAsync(gvapbc); } // return sorted by date else { GetAllPostsByDateViewModelQuery gvapbd = new GetAllPostsByDateViewModelQuery(); vm = await _qpa.ProcessAsync(gvapbd); } return(View(vm)); }
public ActionResult AllPosts(int page = 1, int?categoryId = null) { var query = new QueryInfo() { ItemsPerPage = _PageSize, CategoryId = categoryId, CurrentPage = page, IfIncluded = true }; var result = _unitOfWork.Posts.GetFiltrated(query); var model = new AllPostsViewModel { Categories = _unitOfWork.Categories.GetAll() .Select(Mapper.Map <Category, CategoryDto>).ToList(), Result = result }; return(View(model)); }