public IActionResult Articles(int?pagination)
        {
            ViewBag.NbreVisitUnique = GetVisitIP();
            ViewBag.NbrePagesVues   = GetPageVues();
            UserConnect(ViewBag);
            ConsentCookie(ViewBag);


            List <CategoryArticle> categories = new List <CategoryArticle>();


            if ((ViewBag.Statut == "Coeur") || (ViewBag.Statut == "Administrateur"))
            {
                CategoryArticle c        = new CategoryArticle();
                Article         a        = new Article();
                List <Article>  articles = new List <Article>();

                ArticlesCategoriesViewModel viewModel = new ArticlesCategoriesViewModel {
                    Categories = c.GetAllCategory(), Articles = a.GetAllArticles(pagination, null)
                };                                                                                                                                                          // Ajouter liste articles plus tard

                return(View("ListArticles", viewModel));
            }

            else
            {
                return(RedirectToRoute(new { controller = "Membres", action = "Login" }));
            }
        }
        public IActionResult AddArticle()
        {
            ViewBag.NbreVisitUnique = GetVisitIP();
            ViewBag.NbrePagesVues   = GetPageVues();
            UserConnect(ViewBag);

            if ((ViewBag.Statut == "Coeur") || (ViewBag.Statut == "Administrateur"))
            {
                CategoryArticle        c          = new CategoryArticle();
                List <CategoryArticle> categories = c.GetAllCategory();

                return(View("AddArticle", categories));
            }

            else
            {
                return(RedirectToRoute(new { controller = "Membres", action = "Login" }));
            }
        }
        public async Task <IActionResult> AddArticlePost(string titre, string text, int idCategory, IFormFile media)
        {
            ViewBag.NbreVisitUnique = GetVisitIP();
            ViewBag.NbrePagesVues   = GetPageVues();
            UserConnect(ViewBag);

            CategoryArticle c = new CategoryArticle {
                Id = idCategory
            };

            Membres m = new Membres {
                IdMembre = Convert.ToInt32(ViewBag.Id)
            };

            Article a = new Article {
                Titre = titre, Texte = text, Categorie = c, Auteur = m, Date = DateTime.Now
            };

            a = a.AddArticle();

            string NumeroUnique = Guid.NewGuid().ToString("N");


            var path   = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/images/MediasArticles", a.Id.ToString() + "-" + NumeroUnique + media.FileName);
            var stream = new FileStream(path, FileMode.Create);
            await media.CopyToAsync(stream);

            MediaArticle mediaArticle = new MediaArticle
            {
                Url       = "images/MediasArticles/" + a.Id.ToString() + "-" + NumeroUnique + media.FileName,
                IdArticle = a.Id
            };

            mediaArticle.AddMediaArticle();


            ArticlesCategoriesViewModel viewModel = new ArticlesCategoriesViewModel {
                Categories = c.GetAllCategory(), Articles = a.GetAllArticles(null, null)
            };

            return(View("ListArticles", viewModel));
        }
        public IActionResult Index(int pagination, int category)
        {
            ViewBag.NbreVisitUnique = GetVisitIP();
            ViewBag.NbrePagesVues   = GetPageVues();
            UserConnect(ViewBag);
            ConsentCookie(ViewBag);

            Personnage        p       = new Personnage();
            List <Personnage> Acteurs = p.GetAllPersos();
            Article           a       = new Article();
            CategoryArticle   ca      = new CategoryArticle();

            int NbreArticles = a.GetNbreArticles(category);
            int nbrePagesPagination;

            if (NbreArticles == 0)
            {
                nbrePagesPagination = 1;
            }
            else
            {
                nbrePagesPagination = 0;

                while ((NbreArticles) > 0)
                {
                    nbrePagesPagination++;
                    NbreArticles = NbreArticles - 10;
                }
            }

            int?paginationGetArticles = null;

            if (pagination != 0)
            {
                paginationGetArticles = pagination - 1;
            }



            HomeViewModel viewModel = new HomeViewModel {
                BirthDatesActeurs = Acteurs, Articles = a.GetAllArticles(paginationGetArticles, category), NbrePagePagination = nbrePagesPagination, PagePagination = pagination, CategoryArticles = ca.GetAllCategory(), ActiveCategory = category
            };



            string   remoteIpAddress = Convert.ToString(Request.HttpContext.Connection.RemoteIpAddress);
            Visiteur v = new Visiteur(remoteIpAddress);

            ViewBag.NbreVisitUnique = v.GetVisit(v);
            return(View("Index", viewModel));
        }