Пример #1
0
        public CustomerIndexViewModel(bool showAll, string query)
        {
            Customers = new List<CustomerSummaryViewModel>() { };

            var _cust = from c in db.Customers
                        select c;
            
            //Filtering items if there is a search query.
            if (!String.IsNullOrEmpty(query))
            {
                _cust = _cust.Where(s => (s.FirstName.ToUpper() +" " +s.LastName.ToUpper()).Contains(query.ToUpper()) ||
                s.Email.ToUpper().Contains(query.ToUpper()) || s.CustomerID.ToUpper().Contains(query.ToUpper()));
            }

            //Sort before taking all or just 50. Just using hard-coded sort order for now.
            _cust = _cust.OrderByDescending(x => x.Reviews.Count);

            //After executing search query, limit to 50 by default. If user selected showAll checkbox, this will be 
            //skilled and all customers will be shown (longer load time).
            if (!showAll)
            {
                _cust = _cust.Take(50);
            }

            foreach (var item in _cust.ToList())
            {
                CustomerSummaryViewModel summary = new CustomerSummaryViewModel(item);
                Customers.Add(summary);
            }

        }
Пример #2
0
        public CustomerIndexViewModel(List<Customer> _cust)
        {
            Customers = new List<CustomerSummaryViewModel>() { };

            foreach (var item in _cust)
            {
                CustomerSummaryViewModel summary = new CustomerSummaryViewModel(item);
                Customers.Add(summary);
            }

        }