public ActionResult Index(string searchString)
        {
            var    userId = (int)Session["idu"];
            String Phone2 = userService.GetById(userId).login;
            String mail   = userService.GetById(userId).email;

            ViewBag.home  = mail;
            ViewBag.phone = Phone2;
            List <PublicationVM>      pubs      = new List <PublicationVM>();
            IEnumerable <Publication> pubDomain = Service.GetMany();

            foreach (var pu in pubDomain)
            {
                pubs.Add(new PublicationVM()
                {
                    PublicationId  = pu.PublicationId,
                    nbDislike      = pu.nbDislike,
                    nbLike         = pu.nbLike,
                    datePub        = pu.datePub,
                    imagePub       = pu.imagePub,
                    titlePub       = pu.titlePub,
                    descriptionPub = pu.descriptionPub,
                    ParentFK       = pu.ParentFk
                });
            }


            if (searchString == null)
            {
                return(View(pubs));
            }
            else
            {
                return(View(pubDomain.Where(p => p.titlePub.StartsWith(searchString) || searchString == null).ToList()));
            }
            //return View(Service.GetMany());
        }
Exemplo n.º 2
0
        public List <PublicationVM> Index()
        {
            List <Publication>   publications       = MyService.GetMany().ToList();
            List <PublicationVM> publicationModels1 = new List <PublicationVM>();

            foreach (Publication p in publications)
            {
                publicationModels1.Add(new PublicationVM
                {
                    PublicationId  = p.PublicationId,
                    datePub        = p.datePub,
                    imagePub       = p.imagePub,
                    nbLike         = p.nbLike,
                    nbDislike      = p.nbDislike,
                    titlePub       = p.titlePub,
                    descriptionPub = p.descriptionPub,
                    Dislike        = p.Dislike,
                    Like           = p.Like,
                    ParentFK       = p.ParentFk,
                    nbVue          = p.nbVue
                });
            }
            return(publicationModels1);
        }