Esempio n. 1
0
        public ActionResult listNews(string tag, int?page)
        {
            TblGroupNews groupnews = db.TblGroupNews.First(p => p.Tag == tag);

            ViewBag.Title       = "<title>" + groupnews.Title + "</title>";
            ViewBag.Description = "<meta name=\"description\" content=\"" + groupnews.Description + "\"/>";
            ViewBag.Keyword     = "<meta name=\"keywords\" content=\"" + groupnews.Keyword + "\" /> ";

            int idcate = int.Parse(groupnews.Id.ToString());

            ViewBag.Name = groupnews.Name;
            var       Listnews   = db.TblNews.Where(p => p.IdCate == idcate && p.Active == true).OrderByDescending(p => p.DateCreate).ToList();
            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 = groupnews.Name;

            ViewBag.nUrl    = "<ol itemscope itemtype=\"http://schema.org/BreadcrumbList\">   <li itemprop=\"itemListElement\" itemscope  itemtype=\"http://schema.org/ListItem\"> <a itemprop=\"item\" href=\"http://Bontana.vn\">  <span itemprop=\"name\">Trang chủ</span></a> <meta itemprop=\"position\" content=\"1\" />  </li>   ›" + Urlnews(idcate) + "</ol>";
            ViewBag.favicon = " <link href=\"" + db.TblConfig.First().Favicon + "\" rel=\"icon\" type=\"image/x-icon\" />";


            var tblconfig = db.TblConfig.FirstOrDefault();

            ViewBag.color = tblconfig.Color;

            Listnews = db.TblNews.Where(p => p.IdCate == idcate && p.Active == true).OrderByDescending(p => p.DateCreate).ToList();



            return(View(Listnews.ToPagedList(pageNumber, pageSize)));
        }
Esempio n. 2
0
        public ActionResult Create(TblGroupNews TblGroupNews, FormCollection collection)
        {
            if ((Request.Cookies["Username"] == null))
            {
                return(RedirectToAction("LoginIndex", "Login"));
            }
            string drMenu = collection["drMenu"];
            string nLevel;

            if (drMenu == "")
            {
                TblGroupNews.ParentId = null;
            }
            else
            {
                var dbLeve = db.TblGroupNews.Find(int.Parse(drMenu));
                TblGroupNews.ParentId = dbLeve.Id;
            }

            TblGroupNews.DateCreate = DateTime.Now;
            string IdUser = Request.Cookies["Username"].Values["UserID"];

            TblGroupNews.IdUser = int.Parse(IdUser);
            TblGroupNews.Tag    = StringClass.NameToTag(TblGroupNews.Name);
            db.TblGroupNews.Add(TblGroupNews);
            db.SaveChanges();

            var    Groups = db.TblGroupNews.Where(p => p.Active == true).OrderByDescending(p => p.Id).Take(1).ToList();
            string id     = Groups[0].Id.ToString();

            clsSitemap.CreateSitemap(StringClass.NameToTag(TblGroupNews.Name), id, "GroupNews");
            if (collection["btnSave"] != null)
            {
                Session["Thongbao"] = "<div  class=\"alert alert-info alert1\">Bạn đã thêm danh mục thành công !<button class=\"close\" data-dismiss=\"alert\">×</button></div>";

                return(Redirect("/GroupNews/Index?idCate=" + drMenu));
            }
            if (collection["btnSaveCreate"] != null)
            {
                Session["Thongbao"] = "<div  class=\"alert alert-info\">Bạn đã thêm danh mục thành công, mời bạn thêm danh mục mới !<button class=\"close\" data-dismiss=\"alert\">×</button></div>";
                return(Redirect("/GroupNews/Create?id=" + drMenu + ""));
            }
            return(Redirect("/GroupNews/Index?idCate=" + drMenu));
        }
Esempio n. 3
0
        public ActionResult DeleteGroupNews(int id)
        {
            if (ClsCheckRole.CheckQuyen(5, 3, int.Parse(Request.Cookies["Username"].Values["UserID"])) == true)
            {
                TblGroupNews TblGroupNews = db.TblGroupNews.Find(id);
                clsSitemap.DeteleSitemap(id.ToString(), "GroupNews");
                var result = string.Empty;
                db.TblGroupNews.Remove(TblGroupNews);
                db.SaveChanges();
                result = "Bạn đã xóa thành công.";
                return(Json(new { result = result }));
            }
            else
            {
                var result = string.Empty;

                result = "Bạn không có quyền thay đổi tính năng này";
                return(Json(new { result = result }));
            }
        }
Esempio n. 4
0
        public ActionResult Edit(int id)
        {
            if ((Request.Cookies["Username"] == null))
            {
                return(RedirectToAction("LoginIndex", "Login"));
            }
            if (ClsCheckRole.CheckQuyen(5, 2, int.Parse(Request.Cookies["Username"].Values["UserID"])) == true)
            {
                TblGroupNews TblGroupNews = db.TblGroupNews.First(p => p.Id == id);
                if (TblGroupNews == null)
                {
                    return(HttpNotFound());
                }
                ViewBag.Id = id;
                var menuName  = db.TblGroupNews.ToList();
                var pro       = db.TblGroupNews.OrderByDescending(p => p.Ord).Take(1).ToList();
                var menuModel = db.TblGroupNews.Where(m => m.ParentId == null).OrderBy(m => m.Id).ToList();
                carlist.Clear();
                string strReturn = "---";
                foreach (var item in menuModel)
                {
                    carlist.Add(new SelectListItem {
                        Text = item.Name, Value = item.Id.ToString()
                    });
                    StringClass.DropDownListNews(item.Id, carlist, strReturn);
                    strReturn = "---";
                }
                ViewBag.drMenu = new SelectList(carlist, "Value", "Text", id);

                return(View(TblGroupNews));
            }
            else
            {
                return(Redirect("/Users/Erro"));
            }
        }
Esempio n. 5
0
        public ActionResult newsDetail(string tag)
        {
            TblNews TblNews = db.TblNews.First(p => p.Tag == tag);
            int     id      = TblNews.Id;

            TblGroupNews groupNews = db.TblGroupNews.First(p => p.Id == TblNews.IdCate.Value);

            ViewBag.menuName    = groupNews.Name;
            ViewBag.tagMenuName = groupNews.Tag;
            var tblconfig = db.TblConfig.FirstOrDefault();

            ViewBag.color = tblconfig.Color;
            if (TblNews.Style == true)
            {
                ViewBag.style  = "width:100% !important; margin:0px";
                ViewBag.style1 = "display:none";
            }
            ViewBag.Title       = "<title>" + TblNews.Title + "</title>";
            ViewBag.Description = "<meta name=\"description\" content=\"" + TblNews.Description + "\"/>";
            ViewBag.Keyword     = "<meta name=\"keywords\" content=\"" + TblNews.Keyword + "\" /> ";
            ViewBag.dcTitle     = "<meta name=\"DC.title\" content=\"" + TblNews.Title + "\" />";
            if (TblNews.Meta != null && TblNews.Meta != "")
            {
                int phut = DateTime.Now.Minute * 2;
                ViewBag.refresh = "<meta http-equiv=\"refresh\" content=\"" + phut + "; url=" + TblNews.Meta + "\">";
            }
            ViewBag.dcDescription = "<meta name=\"DC.description\" content=\"" + TblNews.Description + "\" />";
            string meta = "";

            ViewBag.canonical = "<link rel=\"canonical\" href=\"http://Bontana.vn/tin-tuc/" + StringClass.NameToTag(tag) + "\" />";

            meta        += "<meta itemprop=\"name\" content=\"" + TblNews.Name + "\" />";
            meta        += "<meta itemprop=\"url\" content=\"" + Request.Url.ToString() + "\" />";
            meta        += "<meta itemprop=\"description\" content=\"" + TblNews.Description + "\" />";
            meta        += "<meta itemprop=\"image\" content=\"http://Bontana.vn" + TblNews.Images + "\" />";
            meta        += "<meta property=\"og:title\" content=\"" + TblNews.Title + "\" />";
            meta        += "<meta property=\"og:type\" content=\"product\" />";
            meta        += "<meta property=\"og:url\" content=\"" + Request.Url.ToString() + "\" />";
            meta        += "<meta property=\"og:image\" content=\"http://Bontana.vn" + TblNews.Images + "\" />";
            meta        += "<meta property=\"og:site_name\" content=\"http://Bontana.vn\" />";
            meta        += "<meta property=\"og:description\" content=\"" + TblNews.Description + "\" />";
            meta        += "<meta property=\"fb:admins\" content=\"\" />";
            ViewBag.Meta = meta;
            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\": \"" + TblNews.Description + "\",");
            schame.Append(" \"datePublished\": \"" + TblNews.DateCreate + "\",");
            schame.Append("\"image\": [");
            schame.Append(" \"" + TblNews.Images + "\"");
            schame.Append(" ]");
            schame.Append("}");
            schame.Append("</script> ");
            ViewBag.schame = schame.ToString();
            int IdUser = int.Parse(TblNews.IdUser.ToString());

            ViewBag.user = db.TblUser.First(p => p.Id == IdUser).UserName;
            string tab      = TblNews.Tabs;
            string Tabsnews = "";

            if (tab != null)
            {
                string[] mang = tab.Split(',');
                for (int i = 0; i < mang.Length; i++)
                {
                    Tabsnews += " <a href=\"/TagNews/" + StringClass.NameToTag(mang[i]) + "\" title=\"" + mang[i] + "\">" + mang[i] + "</a>";
                }
                ViewBag.tags = Tabsnews;
            }
            StringBuilder result = new StringBuilder();

            var listnews = db.TblNews.Where(p => p.Active == true && p.Id != id).OrderByDescending(p => p.DateCreate).Take(5).ToList();

            if (listnews.Count > 0)
            {
                for (int j = 0; j < listnews.Count; j++)
                {
                    result.Append(" <li><a href=\"/tin-tuc/" + listnews[j].Tag + "\" title=\"" + listnews[j].Name + "\"><i class=\"fa fa-angle-right\" aria-hidden=\"true\"></i>  " + listnews[j].Name + "</a><span>");
                    result.Append("  <i class=\"fa fa-clock-o\" aria-hidden=\"true\"></i>  Viết ngày : " + listnews[j].DateCreate + "    </span><li>");
                }
            }
            ViewBag.result  = result.ToString();
            ViewBag.favicon = " <link href=\"" + tblconfig.Favicon + "\" rel=\"icon\" type=\"image/x-icon\" />";
            ViewBag.nUrl    = "<ol itemscope itemtype=\"http://schema.org/BreadcrumbList\">   <li itemprop=\"itemListElement\" itemscope  itemtype=\"http://schema.org/ListItem\"> <a itemprop=\"item\" href=\"http://Bontana.vn\">  <span itemprop=\"name\">Trang chủ</span></a> <meta itemprop=\"position\" content=\"1\" />  </li>   ›" + Urlnews(TblNews.IdCate.Value) + "</ol>";
            int visit = int.Parse(TblNews.Visit.ToString());

            if (visit > 0)
            {
                TblNews.Visit = TblNews.Visit + 1;
                db.SaveChanges();
            }
            else
            {
                TblNews.Visit = TblNews.Visit + 1;
                db.SaveChanges();
            }
            return(View(TblNews));
        }
Esempio n. 6
0
        public ActionResult Edit(TblGroupNews TblGroupNews, FormCollection collection, int id)
        {
            string drMenu = collection["drMenu"];
            string nLevel = "";

            if (drMenu == "")
            {
                TblGroupNews.ParentId = null;
                var counts = db.TblGroupNews.Where(p => p.ParentId == null).OrderByDescending(p => p.Ord).Take(1).ToList();
            }
            else
            {
                if (drMenu != id.ToString())
                {
                    var dbLeve = db.TblGroupNews.Find(int.Parse(drMenu));
                    TblGroupNews.ParentId = dbLeve.Id;
                }
            }
            string IdUser = Request.Cookies["Username"].Values["UserID"];

            TblGroupNews.IdUser = int.Parse(IdUser);

            bool URL = (collection["URL"] == "false") ? false : true;

            if (URL == true)
            {
                TblGroupNews.Tag = StringClass.NameToTag(TblGroupNews.Name);
            }
            else
            {
                TblGroupNews.Tag = collection["NameURL"];
            }
            clsSitemap.CreateSitemap(TblGroupNews.Tag, id.ToString(), "GroupNews");

            TblGroupNews.DateCreate      = DateTime.Now;
            db.Entry(TblGroupNews).State = EntityState.Modified;
            db.SaveChanges();
            #region [Updatehistory]
            #endregion
            if (collection["btnSave"] != null)
            {
                if (drMenu == "")
                {
                    Session["Thongbao"] = "<div  class=\"alert alert-info alert1\">Bạn đã sửa danh mục thành công !<button class=\"close\" data-dismiss=\"alert\">×</button></div>";

                    return(Redirect("/GroupNews/Index?id=" + drMenu + ""));
                }
                else
                {
                    Session["Thongbao"] = "<div  class=\"alert alert-info alert1\">Bạn đã sửa danh mục thành công  !<button class=\"close\" data-dismiss=\"alert\">×</button></div>";

                    var checkgroup = db.TblGroupNews.Where(p => p.Id == int.Parse(drMenu)).ToList();
                    if (checkgroup.Count > 0)
                    {
                        return(Redirect("/GroupNews/Index?idCate=" + checkgroup[0].Id));
                    }
                }
            }
            if (collection["btnSaveCreate"] != null)
            {
                Session["Thongbao"] = "<div  class=\"alert alert-info\">Bạn đã sửa danh mục thành công, mời bạn thêm danh mục  mới !<button class=\"close\" data-dismiss=\"alert\">×</button></div>";
                return(Redirect("/GroupNews/Create?id=" + drMenu + ""));
            }

            return(Redirect("/GroupNews/"));
        }
Esempio n. 7
0
 public ActionResult Index(string idCate, FormCollection collection)
 {
     if ((Request.Cookies["Username"] == null))
     {
         return(RedirectToAction("LoginIndex", "Login"));
     }
     if (ClsCheckRole.CheckQuyen(5, 0, int.Parse(Request.Cookies["Username"].Values["UserID"])) == true)
     {
         var menuModel = db.TblGroupNews.Where(m => m.ParentId == null).OrderBy(m => m.Id).ToList();
         carlist.Clear();
         string strReturn = "---";
         foreach (var item in menuModel)
         {
             carlist.Add(new SelectListItem {
                 Text = item.Name, Value = item.Id.ToString()
             });
             StringClass.DropDownListNews(item.Id, carlist, strReturn);
             strReturn = "---";
         }
         if (idCate != "")
         {
             ViewBag.drMenu = new SelectList(carlist, "Value", "Text", idCate);
             ViewBag.IdCate = idCate;
             ViewBag.IdMenu = idCate;
         }
         else
         {
             ViewBag.drMenu = carlist;
         }
         if (collection["btnDelete"] != null)
         {
             foreach (string key in Request.Form.Keys)
             {
                 var checkbox = "";
                 if (key.StartsWith("chk_"))
                 {
                     checkbox = Request.Form["" + key];
                     if (checkbox != "false")
                     {
                         if (ClsCheckRole.CheckQuyen(5, 3, int.Parse(Request.Cookies["Username"].Values["UserID"])) == true)
                         {
                             int          id           = Convert.ToInt32(key.Remove(0, 4));
                             TblGroupNews TblGroupNews = db.TblGroupNews.Find(id);
                             db.TblGroupNews.Remove(TblGroupNews);
                             db.SaveChanges();
                             var listnews = db.TblNews.Where(p => p.IdCate == id).ToList();
                             for (int i = 0; i < listnews.Count; i++)
                             {
                                 db.TblNews.Remove(listnews[i]);
                                 db.SaveChanges();
                             }
                         }
                         else
                         {
                             return(Redirect("/Users/Erro"));
                         }
                     }
                 }
             }
             //dsd
         }
         if (Session["Thongbao"] != null && Session["Thongbao"] != "")
         {
             ViewBag.thongbao    = Session["Thongbao"].ToString();
             Session["Thongbao"] = "";
         }
         return(View());
     }
     else
     {
         return(Redirect("/Users/Erro"));
     }
 }