public ActionResult Index(string query, int id = 1) { int page = id - 1; if (query == "") { query = null; } var allIdeas = this.ideas. GetAllWithPaging(page, PageSize) .Where(x => query == null || x.Description.IndexOf(query) >= 0) .To <IdeaViewModel>(); //var ideasCount = this.ideas.GetAll().Count(); var ideasCount = this.ideas.GetAll().Count(); var pageCount = (int)Math.Ceiling(ideasCount / (decimal)PageSize); var ideaIndexModel = new IdeaIndexViewModel() { CreateModel = new IdeaCreateViewModel(), Ideas = allIdeas, PageCount = pageCount, Page = id }; return(this.View(ideaIndexModel)); }
public ActionResult Search(int page = 1, ItemsPerPage itemsPerPage = ItemsPerPage.p05, string Search = "") { if (page <= 0) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, "Parameter 'page' must be positive.")); } int productsPerPage = (int)itemsPerPage; var filters = _ideaRepository.GetNotCancelledIdeasBySearch(Search); int totalPages = (int)Math.Ceiling((double)filters.Count() / (double)productsPerPage); var ideas = filters .OrderByDescending(x => x.EndDate) .Skip((page - 1) * productsPerPage) .Take(productsPerPage) .ToList(); var viewModel = new IdeaIndexViewModel() { Ideas = ideas, Search = Search, TotalPages = totalPages, CurrentPage = page, ItemsPerPage = itemsPerPage, }; return(View(viewModel)); }
public ActionResult Index() { int productsPerPage = 6; var ideas = _ideaRepository.GetNotCancelledIdeasOrderedBy(i => i.EndDate, true) .Take(productsPerPage) .ToList(); var viewModel = new IdeaIndexViewModel() { Ideas = ideas, }; return(View(viewModel)); }
public IActionResult Index() { var ideas = _ideaService.GetAll() .Select(i => new IdeaViewModel { Id = i.Id, UserId = i.UserId, Title = i.Title, Content = i.Content, CreatedDate = i.CreatedDate, EstimatedLevel = i.EstimatedLevel, Level = i.Level }); var model = new IdeaIndexViewModel { Ideas = ideas }; return(View(model)); }