public IActionResult All(int id = 1) { var viewModel = new IndexArticleViewModel { ItemsPerPage = GlobalConstants.ItemsPerPage, PageNumber = id, Articles = this.articlesService.GetAll <ArticleViewModel>(id, GlobalConstants.ItemsPerPage), ItemsCount = this.articlesService.GetCount(), }; return(this.View(viewModel)); }
// GET: Admin/Article public ActionResult Index(int page = 1) { var articles = _articleService.GetArticles(); var articleList = articles.Select(Mapper.Map <Article, ArticleViewModel>).Skip((page - 1) * _pageSize).Take(_pageSize).ToList(); var pager = new Pager(page, articles.Count, _pageSize); var model = new IndexArticleViewModel { Articles = articleList, Pager = pager }; return(View(model)); }
// GET: Articles public IActionResult Index(string MotCle, string CategorieArticle) { List <IndexArticleViewModel> ArticleVMList = new List <IndexArticleViewModel>(); var garderieContext = _context.Articles.Include(a => a.Categorie).Include(a => a.EnfantInventaire).Include(a => a.Inventaire); /*var articles = from a in garderieContext * select a;*/ ServiceReference2.GarderieServiceClient serv = new ServiceReference2.GarderieServiceClient(); var articles = serv.GetAllArticlesAsync().Result; IQueryable <string> categories = from ca in _context.CategoriesArticle join a in garderieContext on ca.CategorieId equals a.CategorieId orderby ca.CategorieId select ca.Nom; if (!String.IsNullOrEmpty(MotCle)) { articles = articles.Where(s => s.nom.Contains(MotCle) || s.Description.Contains(MotCle)).ToArray(); } if (!String.IsNullOrEmpty(CategorieArticle)) { var categorie = _context.CategoriesArticle.FirstOrDefault(ca => ca.Nom == CategorieArticle).CategorieId; articles = articles.Where(x => x.Categorie.idCategorie == categorie).ToArray(); } if (!articles.Any()) { articles = serv.GetAllArticlesAsync().Result; } foreach (var article in articles) { IndexArticleViewModel viewModel = new IndexArticleViewModel { ArticleId = article.idArticle, Nom = article.nom, Quantite = (int)article.quantite, Photo = article.Photo, Description = article.Description, Categorie = article.Categorie.nom, Categories = new SelectList(categories.Distinct().ToList()) }; ArticleVMList.Add(viewModel); } return(View(ArticleVMList)); }
public IActionResult Index(IndexArticleViewModel viewModel) { viewModel.Articles = ArticleService.GiveRandomArticles().Take(10).ToList(); return(View(viewModel)); }