Ejemplo n.º 1
0
        public List <ArticlesVM> GetAllArticles()
        {
            List <ArticlesVM> ArtList = new List <ArticlesVM>();
            List <Article>    art     = bdd.Articles.ToList();

            foreach (var item in art)
            {
                ArticlesVM articleApi = new ArticlesVM();

                articleApi.Id          = item.ID;
                articleApi.Pseudo      = item.Pseudo;
                articleApi.Titre       = item.Titre;
                articleApi.Contenu     = item.Contenu;
                articleApi.ImageName   = item.ImageName;
                articleApi.Publication = item.Publication.ToString("dd/MM/yyyy à HH mm");
                articleApi.EstPublie   = item.EstPublie;
                articleApi.NbrCom      = item.Commentaires.Count();

                ArtList.Add(articleApi);
            }



            return(ArtList);
        }
Ejemplo n.º 2
0
        public async Task <ArticlesVM> Articles()
        {
            var articles = await apiClient.GetArticlesAsync();

            var vm = new ArticlesVM
            {
                Articles = articles
            };

            return(vm);
        }
Ejemplo n.º 3
0
        public ArticlesVM GetArticle(int id)
        {
            Article    art        = bdd.Articles.Find(id);
            ArticlesVM articleApi = new ArticlesVM();

            articleApi.Id          = art.ID;
            articleApi.Pseudo      = art.Pseudo;
            articleApi.Titre       = art.Titre;
            articleApi.Contenu     = art.Contenu;
            articleApi.ImageName   = art.ImageName;
            articleApi.Publication = art.Publication.ToString("dd/MM/yyyy");
            articleApi.EstPublie   = art.EstPublie;

            articleApi.NbrCom = art.Commentaires.Count();

            return(articleApi);
        }
        public ActionResult Details(int id)
        {
            ArticlesDTO articleDTO;
            ArticlesVM  articleVM;

            using (Db db = new Db())
            {
                articleDTO = db.Articles.Find(id);
                articleVM  = new ArticlesVM(articleDTO);
                //TempData["author_name"] = db.Users.Where(x => x.User_Id == articleVM.Id_Author).Select(x => x.Login);

                Random rand   = new Random();
                int    toSkip = rand.Next(1, db.Articles.Count());
                TempData["random_id"] = db.Articles.OrderBy(r => Guid.NewGuid()).Skip(toSkip).Select(x => x.Id_Article).Take(1).First();
            }

            return(View(articleVM));
        }