Esempio n. 1
0
        /// <summary>
        /// 首页搜索
        /// </summary>
        public ActionResult Search(int? id)
        {
            HomeSearchViewData viewData = new HomeSearchViewData() { lsNews = new List<News>() };
            string keyword = Request.QueryString["k"];
            if (keyword == null || keyword == "")
            { return View(viewData); }
            int p = 1;
            try
            {
                p = int.Parse(Request.QueryString["p"]);
            }
            catch
            { }

            if (id == null)
            {
                id = (int?)1;
            }
            Expression condition = Expression.Constant(false);
            ParameterExpression parameter = Expression.Parameter(typeof(News), "n");
            Expression con = Expression.Call(Expression.Property(parameter, typeof(News).GetProperty("Title")), typeof(string).GetMethod("Contains", new Type[] { typeof(string) }), Expression.Constant(keyword));
            Expression con1 = Expression.Call(Expression.Property(parameter, typeof(News).GetProperty("PubAuthor")), typeof(string).GetMethod("Contains", new Type[] { typeof(string) }), Expression.Constant(keyword));
            Expression ture = Expression.Or(con, con1);
            Expression<Func<News, bool>> end = Expression.Lambda<Func<News, bool>>(ture, new ParameterExpression[] { parameter });
            List<News> result = CQGJ.News.Where(end).OrderBy(n => n.PubDate).ToList();
            viewData.lsNews = result.Skip(30 * (id.Value - 1)).Take(30).ToList();
            UrlManager urlManager = new DefaultUrlManager(result.Count, 30, "p");
            Pager pager = new Pager(urlManager);
            viewData.PagerString = pager.PagerString;
            return View(viewData);
        }
Esempio n. 2
0
        /// <summary>
        /// 首页搜索
        /// </summary>
        public void HomeSearch(int? id)
        {
            HomeSearchViewData viewData = new HomeSearchViewData(){ lsNews=new List<News>() };

            viewData.lsHotNews = (from hn in CQGJ.News
                                  where hn.IsNotify == false && hn.IsApproval == true && hn.Status == (int?)NewsStatus.Approved
                                  orderby hn.PubDate descending
                                  select hn).Take(5).ToList();
            viewData.lsCountNews = (from cn in CQGJ.News
                                    where cn.IsNotify == false && cn.IsApproval == true && cn.Status == (int?)NewsStatus.Approved
                                    orderby cn.ViewNum descending
                                    select cn).Take(5).ToList();
            if (GetString("keyword") != "" || id != null)
            {
                if (id == null)
                {
                    id = (int?)1;
                }
                Expression condition = Expression.Constant(false);
                ParameterExpression parameter = Expression.Parameter(typeof(News), "n");
                Expression con = Expression.Call(Expression.Property(parameter, typeof(News).GetProperty("Title")), typeof(string).GetMethod("Contains", new Type[] { typeof(string) }), Expression.Constant(GetString("keyword")));
                Expression con1 = Expression.Call(Expression.Property(parameter, typeof(News).GetProperty("PubAuthor")), typeof(string).GetMethod("Contains", new Type[] { typeof(string) }), Expression.Constant(GetString("keyword")));
                Expression ture = Expression.Or(con, con1);
                Expression<Func<News, bool>> end = Expression.Lambda<Func<News, bool>>(ture, new ParameterExpression[] { parameter });
                List<News> result = CQGJ.News.Where(end).OrderBy(n => n.PubDate).ToList();
                viewData.lsNews = result.Skip(20 * (id.Value - 1)).Take(20).ToList();
                UrlManager urlManager = new DefaultUrlManager(result.Count, 20);
                Pager pager = new Pager(urlManager);
                viewData.PagerString = pager.PagerString;
                RenderView("HomeSearch", viewData);
            }
            else
            {
                RenderView("HomeSearch", viewData);
            }
        }