コード例 #1
0
        public ActionResult Tabsnews(string tag, int?page)
        {
            tag = StringClass.NameToTag(tag);;
            string[] Mang1    = StringClass.COnvertToUnSign1(tag).Split('-');
            string   chuoitag = "";

            for (int i = 0; i < Mang1.Length; i++)
            {
                if (i == 0)
                {
                    chuoitag += Mang1[i];
                }
                else
                {
                    chuoitag += " " + Mang1[i];
                }
            }
            int           dem      = 1;
            string        name     = "";
            List <tblNew> ListNew  = (from c in db.tblNews where c.Active == true select c).ToList();
            List <tblNew> listnews = ListNew.FindAll(delegate(tblNew math)
            {
                if (math.Tabs != null && math.Tabs != "")
                {
                    if (StringClass.COnvertToUnSign1(math.Tabs.ToUpper()).Contains(chuoitag.ToUpper()))
                    {
                        string[] Manghienthi = math.Tabs.Split(',');
                        foreach (var item in Manghienthi)
                        {
                            if (dem == 1)
                            {
                                var kiemtra = StringClass.COnvertToUnSign1(item.ToUpper()).Contains(chuoitag.ToUpper());
                                if (kiemtra == true)
                                {
                                    name = item;
                                    dem  = 0;
                                }
                            }
                        }

                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }


                else
                {
                    return(false);
                }
            }
                                                     );
            const int pageSize   = 20;
            var       pageNumber = (page ?? 1);
            // Thiết lập phân trang
            var ship = new PagedListRenderOptions
            {
                DisplayLinkToFirstPage                      = PagedListDisplayMode.Always,
                DisplayLinkToLastPage                       = PagedListDisplayMode.Always,
                DisplayLinkToPreviousPage                   = PagedListDisplayMode.Always,
                DisplayLinkToNextPage                       = PagedListDisplayMode.Always,
                DisplayLinkToIndividualPages                = true,
                DisplayPageCountAndCurrentLocation          = false,
                MaximumPageNumbersToDisplay                 = 5,
                DisplayEllipsesWhenNotShowingAllPageNumbers = true,
                EllipsesFormat                     = "&#8230;",
                LinkToFirstPageFormat              = "Trang đầu",
                LinkToPreviousPageFormat           = "«",
                LinkToIndividualPageFormat         = "{0}",
                LinkToNextPageFormat               = "»",
                LinkToLastPageFormat               = "Trang cuối",
                PageCountAndCurrentLocationFormat  = "Page {0} of {1}.",
                ItemSliceAndTotalFormat            = "Showing items {0} through {1} of {2}.",
                FunctionToDisplayEachPageNumber    = null,
                ClassToApplyToFirstListItemInPager = null,
                ClassToApplyToLastListItemInPager  = null,
                ContainerDivClasses                = new[] { "pagination-container" },
                UlElementClasses                   = new[] { "pagination" },
                LiElementClasses                   = Enumerable.Empty <string>()
            };

            ViewBag.ship = ship;
            ViewBag.name = name;

            ViewBag.Title       = "<title>" + name + "</title>";
            ViewBag.Description = "<meta name=\"description\" content=\"" + name + "\"/>";
            ViewBag.Keyword     = "<meta name=\"keywords\" content=\"" + name + "\" /> ";
            ViewBag.favicon     = " <link href=\"" + db.tblConfigs.First().Favicon + "\" rel=\"icon\" type=\"image/x-icon\" />";
            ViewBag.canonical   = "<link rel=\"canonical\" href=\"http://Thayloilocnuoc.com/TagNews/" + StringClass.NameToTag(chuoitag) + "\" />";;
            StringBuilder schame = new StringBuilder();

            schame.Append("<script type=\"application/ld+json\">");
            schame.Append("{");
            schame.Append("\"@context\": \"http://schema.org\",");
            schame.Append("\"@type\": \"NewsArticle\",");
            schame.Append("\"headline\": \"" + name + "\",");
            schame.Append(" \"datePublished\": \"\",");
            schame.Append("\"image\": [");
            schame.Append(" \"\"");
            schame.Append(" ]");
            schame.Append("}");
            schame.Append("</script> ");
            ViewBag.schame = schame.ToString();
            return(View(listnews.ToPagedList(pageNumber, pageSize)));
        }
コード例 #2
0
        public ActionResult tagNews(string tag, int?page)
        {
            string[] Mang1    = StringClass.COnvertToUnSign1(tag).Split('-');
            string   chuoitag = "";

            for (int i = 0; i < Mang1.Length; i++)
            {
                if (i == 0)
                {
                    chuoitag += Mang1[i];
                }
                else
                {
                    chuoitag += " " + Mang1[i];
                }
            }
            int           dem      = 1;
            string        name     = "";
            List <tblNew> ListNew  = (from c in db.tblNews where c.Active == true select c).ToList();
            List <tblNew> listnews = ListNew.FindAll(delegate(tblNew math)
            {
                if (StringClass.COnvertToUnSign1(math.Keyword.ToUpper()).Contains(chuoitag.ToUpper()))
                {
                    string[] Manghienthi = math.Keyword.Split(',');
                    foreach (var item in Manghienthi)
                    {
                        if (dem == 1)
                        {
                            var kiemtra = StringClass.COnvertToUnSign1(item.ToUpper()).Contains(chuoitag.ToUpper());
                            if (kiemtra == true)
                            {
                                name = item;
                                dem  = 0;
                            }
                        }
                    }

                    return(true);
                }

                else
                {
                    return(false);
                }
            }
                                                     );
            const int pageSize   = 10;
            var       pageNumber = (page ?? 1);
            var       ship       = new PagedListRenderOptions
            {
                DisplayLinkToFirstPage                      = PagedListDisplayMode.Always,
                DisplayLinkToLastPage                       = PagedListDisplayMode.Always,
                DisplayLinkToPreviousPage                   = PagedListDisplayMode.Always,
                DisplayLinkToNextPage                       = PagedListDisplayMode.Always,
                DisplayLinkToIndividualPages                = true,
                DisplayPageCountAndCurrentLocation          = false,
                MaximumPageNumbersToDisplay                 = 5,
                DisplayEllipsesWhenNotShowingAllPageNumbers = true,
                EllipsesFormat                     = "&#8230;",
                LinkToFirstPageFormat              = "Trang đầu",
                LinkToPreviousPageFormat           = "«",
                LinkToIndividualPageFormat         = "{0}",
                LinkToNextPageFormat               = "»",
                LinkToLastPageFormat               = "Trang cuối",
                PageCountAndCurrentLocationFormat  = "Page {0} of {1}.",
                ItemSliceAndTotalFormat            = "Showing items {0} through {1} of {2}.",
                FunctionToDisplayEachPageNumber    = null,
                ClassToApplyToFirstListItemInPager = null,
                ClassToApplyToLastListItemInPager  = null,
                ContainerDivClasses                = new[] { "pagination-container" },
                UlElementClasses                   = new[] { "pagination" },
                LiElementClasses                   = Enumerable.Empty <string>()
            };

            ViewBag.ship = ship;

            ViewBag.Name        = name;
            ViewBag.nUrl        = "<a href=\"/\" title=\"Trang chủ\" rel=\"nofollow\"><span class=\"iCon\"></span> Trang chủ</a><i></i> " + name + "";
            ViewBag.Title       = "<title>" + name + "</title>";
            ViewBag.Description = "<meta name=\"description\" content=\"" + name + "\"/>";
            ViewBag.Keyword     = "<meta name=\"keywords\" content=\"" + name + "\" /> ";
            return(View(listnews.ToPagedList(pageNumber, pageSize)));
        }