예제 #1
0
        public ActionResult chitiet(string ID)
        {
            try
            {
                if (objUtil.fBrowserIsMobile())
                {
                    return(RedirectToAction("chitiet", "mtinnhanh247", new { ID = ID }));
                }
                //var arrtemp = ID.Split('-');
                //string strFeedId = arrtemp[arrtemp.Length - 1];
                //lấy 1 mẫu tin cho phần 2
                DBContext      context = HttpContext.RequestServices.GetService(typeof(DBContext)) as DBContext;
                List <NewsRes> lstNews = context.GetAllNewsRes() as List <NewsRes>;
                NewsRes        it2News = lstNews.Where(c => c.NewsID == Convert.ToInt32(ID)).FirstOrDefault();
                //cung danh muc
                NewsRes        it3News  = lstNews.Where(c => c.TypeID == it2News.TypeID).Skip(1).OrderByDescending(c => c.ViewNumber).FirstOrDefault();
                NewsRes        it4News  = lstNews.Where(c => c.TypeID == it2News.TypeID).Skip(2).Take(1).OrderByDescending(c => c.ViewNumber).FirstOrDefault();
                List <NewsRes> lst5News = lstNews.Where(c => c.TypeID == it2News.TypeID).OrderByDescending(c => c.ViewNumber).Skip(3).Take(4).ToList();

                ViewBag.itDetail2 = it2News;
                ViewBag.itDetail3 = it3News;
                ViewBag.itDetail4 = it4News;
                ViewBag.itDetail5 = lst5News;

                //update viewnumber
                context.Update(Convert.ToInt32(ID));
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(View());
        }
        public ActionResult chitiet(string ID)
        {
            if (!Regex.IsMatch(ID, @"\d"))
            {
                return(RedirectToAction("trangchu", "mtinnhanh247"));
            }
            if (!objUtil.fBrowserIsMobile())
            {
                return(RedirectToAction("chitiet", "tinnhanh247", new { ID = ID }));
            }
            //lấy 1 mẫu tin cho phần 2
            DBContext      context = HttpContext.RequestServices.GetService(typeof(DBContext)) as DBContext;
            List <NewsRes> lstNews = context.GetAllNewsRes() as List <NewsRes>;
            NewsRes        it1News = lstNews.Where(c => c.NewsID == Convert.ToInt32(ID)).FirstOrDefault();
            //cung danh muc
            List <NewsRes> lst2News = lstNews.Where(c => c.TypeID == it1News.TypeID && c.NewsID != it1News.NewsID).OrderByDescending(c => c.ViewNumber).Take(3).ToList();
            //dang hot
            List <NewsRes> lst3News = lstNews.OrderByDescending(c => c.ViewNumber).Take(3).ToList();

            ViewBag.it1 = it1News;
            ViewBag.it2 = lst2News;
            ViewBag.it3 = lst3News;
            context.Update(Convert.ToInt32(ID));
            return(View());
        }
        // GET: mtinnhanh247
        public ActionResult trangchu()
        {
            if (!objUtil.fBrowserIsMobile())
            {
                return(RedirectToAction("trangchu", "tinnhanh247"));
            }
            DBContext      context = HttpContext.RequestServices.GetService(typeof(DBContext)) as DBContext;
            List <NewsRes> lstNews = context.GetAllNewsRes() as List <NewsRes>;
            //lấy 1 mẫu tin cho phần 1
            NewsRes it1News = lstNews.Where(c => c.TypeID == 7).Take(1).FirstOrDefault();
            //lấy 8 mẫu tin cho phần 2
            List <NewsRes> it2News = lstNews.Where(c => c.TypeID == 7).Skip(1).Take(8).ToList();
            //lấy 8 mẫu tin cho phần 3
            List <NewsRes> lst3News = lstNews.Where(c => c.TypeID == 6).Take(8).ToList();
            //lấy 8 mẫu tin cho phần 4 (mới nhất)
            List <NewsRes> lst4News = lstNews.Where(c => c.TypeID == 10).Take(5).ToList();
            //lấy 50 mẫu tin cho phần 5
            List <int>     id2      = it2News.Select(c => c.NewsID).ToList();
            List <int>     id3      = lst3News.Select(c => c.NewsID).ToList();
            List <int>     id4      = lst4News.Select(c => c.NewsID).ToList();
            List <NewsRes> lst5News = lstNews.Where(c => !id2.Contains(c.NewsID) && !id3.Contains(c.NewsID) && !id4.Contains(c.NewsID)).Take(50).ToList();

            ViewBag.it1 = it1News;
            ViewBag.it2 = it2News;
            ViewBag.it3 = lst3News;
            ViewBag.it4 = lst4News;
            ViewBag.it5 = lst5News;
            return(View());
        }
예제 #4
0
        //private IRepositories _ObjRepositories;
        //public tinnhanh247Controller(IRepositories ObjRepositories)
        //{
        //    _ObjRepositories = ObjRepositories;
        //}
        public ActionResult trangchu()
        {
            //string sql = "select NewsID,title,TypeID,MenuID,SourceID,ImageTH,ImageFull,ShortContent,Content,ViewNumber,CreatedDate from news order by CreatedDate desc limit 500";
            //List<NewsReponse> Lst = _ObjRepositories.ReadAll<NewsReponse>(sql);

            if (objUtil.fBrowserIsMobile())
            {
                return(RedirectToAction("trangchu", "mtinnhanh247"));
            }
            DBContext      context = HttpContext.RequestServices.GetService(typeof(DBContext)) as DBContext;
            List <NewsRes> lstNews = context.GetAllNewsRes() as List <NewsRes>;
            ////lấy 1 mẫu tin cho phần 1
            //NewsRes it1News = lstNews.Where(c => c.TypeID == 10).Take(1).FirstOrDefault();
            ////lấy 1 mẫu tin cho phần 2
            //NewsRes it2News = lstNews.Where(c => c.TypeID == 2).Take(1).FirstOrDefault();
            ////lấy 8 mẫu tin cho phần 3
            //List<NewsRes> lst3News = lstNews.Where(c => c.TypeID == 7).Take(8).ToList();
            ////lấy 4 mẫu tin cho phần 4
            //List<NewsRes> lst4News = lstNews.Where(c => c.TypeID == 10).Take(4).ToList();
            ////lấy 25 mẫu tin cho phần 5 (tin moi nhat)
            //List<NewsRes> lst5News = lstNews.Where(c => c.TypeID == 6).Take(25).ToList();
            ////lấy 12 mẫu tin đừng bỏ lỡ
            //List<NewsRes> lst6News = lstNews.OrderByDescending(c => c.ViewNumber).Take(12).ToList();


            //lấy 1 mẫu tin cho phần 1
            NewsRes it1News = lstNews.Where(c => c.TypeID == 6).Take(1).FirstOrDefault();

            //lấy 1 mẫu tin cho phần 2
            NewsRes it2News = lstNews.Where(c => c.TypeID == 2).Take(1).FirstOrDefault();
            //lấy 8 mẫu tin cho phần 3
            List <NewsRes> lst3News = lstNews.Where(c => c.TypeID == 3).Take(8).ToList();
            //lấy 4 mẫu tin cho phần 4
            List <NewsRes> lst4News = lstNews.Where(c => c.TypeID == 4).Take(4).ToList();
            //lấy 25 mẫu tin cho phần 5 (tin moi nhat)
            List <NewsRes> lst5News = lstNews.Where(c => c.TypeID == 6).Take(25).ToList();
            //lấy 12 mẫu tin đừng bỏ lỡ
            List <NewsRes> lst6News = lstNews.OrderByDescending(c => c.ViewNumber).Take(12).ToList();

            ViewBag.it1 = it1News;
            ViewBag.it2 = it2News;
            ViewBag.it3 = lst3News;
            ViewBag.it4 = lst4News;
            ViewBag.it5 = lst5News;
            ViewBag.it6 = lst6News;
            return(View());
        }
        public ActionResult danhmuc(string Alias, string ID)
        {
            if (!objUtil.fBrowserIsMobile())
            {
                return(RedirectToAction("danhmuc", "tinnhanh247", new { ID = ID }));
            }
            DBContext      context = HttpContext.RequestServices.GetService(typeof(DBContext)) as DBContext;
            List <NewsRes> lstNews = context.GetAllNewsRes() as List <NewsRes>;
            //lấy 1 mẫu tin cho phần 1
            NewsRes it1News = lstNews.Where(c => c.TypeID == Convert.ToInt32(ID)).Take(1).FirstOrDefault();
            //lấy 8 mẫu tin cho phần 2
            List <NewsRes> it2News = lstNews.Where(c => c.TypeID == Convert.ToInt32(ID) && c.NewsID != it1News.NewsID).OrderByDescending(c => c.ViewNumber).Take(8).ToList();
            //lấy 50 mẫu tin cho phần 5.
            List <int>     id2      = it2News.Select(c => c.NewsID).ToList();
            List <NewsRes> lst3News = lstNews.Where(c => c.TypeID == Convert.ToInt32(ID) && c.NewsID != it1News.NewsID && !id2.Contains(c.NewsID)).OrderByDescending(c => c.ViewNumber).Take(50).ToList();

            ViewBag.it1 = it1News;
            ViewBag.it2 = it2News;
            ViewBag.it3 = lst3News;
            return(View());
        }