コード例 #1
0
        //
        // GET: /Backend/Article/

        public ActionResult Index(QueryOption <ArticleViewModel> queryOption)
        {
            var article = db.Article.Include(a => a.Category)
                          .Select(x => new ArticleViewModel
            {
                ID          = x.ID,
                CategoryID  = x.CategoryID,
                Category    = x.Category,
                Subject     = x.Subject,
                Summary     = x.Summary,
                ContentText = x.ContentText,
                IsPublish   = x.IsPublish,
                ViewCount   = x.ViewCount,
                PublishDate = x.PublishDate,
                CreateUser  = x.CreateUser,
                CreateDate  = x.CreateDate,
                UpdateUser  = x.UpdateUser,
                UpdateDate  = x.UpdateDate
            });

            if (!string.IsNullOrEmpty(queryOption.Keyword))
            {
                article = article.Where(x => x.Subject.Contains(queryOption.Keyword) ||
                                        x.ContentText.Contains(queryOption.Keyword));
            }

            queryOption.SetSource(article);

            return(View(queryOption));
        }
コード例 #2
0
        // GET: backend/Admin
        public ActionResult Index(int?page, string q, string column = "Date", EnumSort order = EnumSort.Ascending)
        {
            //分頁套件: Install-Package PagedList.Mvc
            var pageIndex = page.HasValue ? page.Value < 1 ? 1 : page.Value : 1;
            var pageSize  = 10;

            //為了範例最簡化,因此直接在 Controller 操作 DB ,實務上請盡量避免
            var source = _AccountBookSvc.Lookup().AsQueryable();//_dbContext.AccountBook.AsQueryable();

            if (string.IsNullOrWhiteSpace(q) == false)
            {
                // 只是單純示範搜尋條件應該如何累加
                var category = Convert.ToInt32(q);
                source = source.Where(d => d.Category == category);
            }

            var result = new QueryOption <AccountBook.Models.AccountBook>
            {
                Order    = order,
                Column   = column,
                Page     = pageIndex,
                PageSize = pageSize,
                Keyword  = q
            };

            //利用 SetSource 將資料塞入(塞進去之前不能將資料讀出來)
            result.SetSource(source);
            ViewData.Model = result;
            return(View());
            //return View(_AccountBookSvc.Lookup());
        }
コード例 #3
0
        public ActionResult Index(QueryOption <Category> queryOption)
        {
            var query = db.Category.AsQueryable();

            if (!string.IsNullOrEmpty(queryOption.Keyword))
            {
                query = query.Where(a => a.Name.Contains(queryOption.Keyword));
            }

            queryOption.SetSource(query);

            return(View(queryOption));
        }
コード例 #4
0
        //
        // GET: /Backend/User/

        public ActionResult Index(QueryOption <SystemUser> queryOption)
        {
            var query = db.SystemUser.AsQueryable();

            if (!string.IsNullOrEmpty(queryOption.Keyword))
            {
                query = query.Where(x => x.Name.Contains(queryOption.Keyword));
            }

            queryOption.SetSource(query);

            return(View(queryOption));
        }
コード例 #5
0
        /// <summary>
        /// test
        /// Indexes the specified query model.
        /// </summary>
        /// <param name="queryModel">The query model.</param>
        /// <returns>ActionResult.</returns>
        public ActionResult Index(QueryOption <Article> queryModel)
        {
            var query = db.Article.AsQueryable();

            if (!string.IsNullOrEmpty(queryModel.Keyword))
            {
                query = query.Where(a => a.Subject.Contains(queryModel.Keyword)
                                    ||
                                    a.ContentText.Contains(queryModel.Keyword));
            }

            queryModel.SetSource(query);

            return(View(queryModel));
        }