public ActionResult Index(CustomersQueryViewModel cond = null)
        {
            CustomersQueryViewModel result = new CustomersQueryViewModel();

            if (cond == null)
            {
                //預設排序
                result.Sort.Column = "Id";
                result.Sort.Sort   = "desc";
            }
            var customerList = CustomerRepo.Search(cond.Query, cond.Paging, cond.Sort).Select(x => new CustomersViewModel()
            {
                Address          = x.地址,
                ClientName       = x.客戶名稱,
                CompanyNumber    = x.統一編號,
                CustomerTypeName = x.客戶類別.類別名稱,
                Email            = x.Email,
                Fax   = x.傳真,
                Phone = x.電話,
                Id    = x.Id
            });

            result.Paging.Count     = CustomerRepo.SearchCount(cond.Query);
            result.Customers        = new StaticPagedList <CustomersViewModel>(customerList, cond.Paging.Page, cond.Paging.Take, result.Paging.Count);
            result.CustomerTypeList = CustomerTypeRepo.All().ToList().Select(x => new SelectListItem()
            {
                Text     = x.類別名稱,
                Value    = x.Id.ToString(),
                Selected = cond != null ?
                           cond.Query.CustomerTypeId.HasValue ?
                           x.Id == cond.Query.CustomerTypeId.Value ? true : false
                               : false
                           : false
            }).ToList();
            result.Paging.Take = cond.Paging.Take;
            result.Query       = cond.Query;
            return(View(result));
        }
示例#2
0
        // GET: 客戶資料
        public ActionResult Index(客戶資料QueryOption query)
        {
            ViewBag.CategoryList = customerRepository.Get客戶分類()
                                   .ToArray()
                                   .Select(c => new SelectListItem()
            {
                Selected = c == query.Category,
                Text     = string.IsNullOrEmpty(c) ? "全部" : c,
                Value    = c,
            });

            var 客戶資料 = customerRepository.Search(query.Keyword, query.Category)
                       .OrderBy(query.GetSortString())
                       .ToPagedList(query.Page, query.GetPageSize());

            ViewBag.QueryOption = query;

            return(View(客戶資料));
        }