using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic;

namespace BusinessServices
{
    public static class CustomersProvider
    {
        public static IEnumerable<Customer> GetAll(int startIndex, int maxRows, string filterExpressions,
                                                   string sortExpressions)
        {
            using (var db = new NorthwindDataContext())
            {
                IQueryable<Customer> customers = db.Customers;
                if (!string.IsNullOrEmpty(filterExpressions))
                    customers = customers.Where(filterExpressions);
                if (!string.IsNullOrEmpty(sortExpressions))
                    customers = customers.OrderBy(sortExpressions);
                return customers.Skip(startIndex).Take(maxRows).ToList();
            }
        }

        public static int GetCount(string filterExpressions)
        {
            using (var db = new NorthwindDataContext())
            {
                IQueryable<Customer> customers = db.Customers;
                if (!string.IsNullOrEmpty(filterExpressions))
                    customers = customers.Where(filterExpressions);

                return customers.Count();
            }
        }
    }
}