public NewsVM GetNews(NewsFilterVM filter, int page) { NewsVM model = new NewsVM(); int pageSize = 2; var query = _newsRepo.GetAll(); if (!string.IsNullOrEmpty(filter.Name)) { query = query.Where(x => x.Name.Contains(filter.Name)); } if (filter.Id != 0) { query = query.Where(x => x.Id == filter.Id); } int pageNo = page - 1; model.list = query.OrderBy(x => x.Id) .Skip(pageNo * pageSize) .Take(pageSize) .ToList(); int allCount = query.Count(); model.Page = page; model.maxPage = (int)Math.Ceiling((double)allCount / pageSize); model.NewsFilter = filter; return(model); }
public ActionResult Index(int?page) { var currentPage = page ?? 1; var news = _newsRepo.GetAll().OrderByDescending(x => x.PublishDate); var users = _userRepo.GetAllUsers(); var model = new NewsUsersViewModel() { NewsPagedList = new PagedList <News>(news, currentPage, Constants.NewsPerPage), PartnerUser = users }; //new PagedList<News>(news, currentPage, Constants.NewsPerPage); return(View(model)); }
public async Task <IActionResult> GetAll() { try { var news = await _repo.GetAll(); var newsToShow = _mapper.Map <List <NewsToShow> >(news); return(Ok(newsToShow)); } catch (System.Exception) { return(BadRequest()); } }
// GET: News public IActionResult Index() { return(View(_NewsRepo.GetAll())); }