public ActionResult Articles() { var model = new HomeArticles(); model.Articles = Db.Article.ToList(); return(View(model)); }
// GET: api/Articles public IHttpActionResult GetArticle() { var articles = new List <ViewArticleJournalist>(); //ViewModelJournalist jr = new ViewModelJournalist(); using (var context = new NewsEntities()) { //var article = context.Article.ToList(); var status = "posted"; var article = context.Article.Where(f => f.Status == status).ToList().OrderByDescending(a => a.Date).Take(12); if (article == null) { return(NotFound()); } foreach (var n in article) { ViewArticleJournalist vm = new ViewArticleJournalist(); vm.ID = n.ID; vm.img = n.Img; vm.Titre = n.Titre; vm.body = n.Body; vm.Date = n.Date; vm.Journalistes = new JournalisteInfo(); vm.Journalistes.Nom = n.Journalistes.Nom; vm.Journalistes.Id = n.Journalistes.ID; vm.Journalistes.Prenom = n.Journalistes.Prenom; vm.Journalistes.Image = n.Journalistes.Image; articles.Add(vm); vm.Categorie = (int)n.CategorieID; } } HomeArticles ha = new HomeArticles(); ha._4articles = articles.GetRange(0, 4); ha._8articles = articles.GetRange(4, 8); return(Ok(ha)); //return db.Article; }