// GET: Customers
 public ActionResult CustomerList()
 {
     var model = new CustomerListViewModel
     {
         Customers = GetCustomers().ToList()
     };
     ViewBag.CustomerClassificationID = new SelectList(Db.CustomerClassifications, "ID", "Name");
     ViewBag.CityID = new SelectList(Db.Cities, "ID", "Name");
     ViewBag.CityRegionID = new SelectList(Db.CityRegions, "ID", "Name");
     if (User.IsInRole("Admin")) ViewBag.SellerID = new SelectList(Db.Users, "ID", "Email");
     return View(model);
 }
        public ActionResult SearchCustomer([Bind(Include = "Name,CityID,CityRegionID,CustomerClassificationID,Gender,LastPurchaseInitialDate,LastPurchaseFinalDate, SellerID")]FilterCustomerViewModel filters)
        {
            var customers = GetCustomers();

            if (!String.IsNullOrEmpty(filters.CustomerClassificationID))
                customers = customers.Where(c => c.Classification.ID.ToString().Equals(filters.CustomerClassificationID));

            if (!String.IsNullOrEmpty(filters.Name))
                customers = customers.Where(c => c.Name.Contains(filters.Name));

            if (!String.IsNullOrEmpty(filters.CityID))
                customers = customers.Where(c => c.CityRegion.City.ID.ToString().Equals(filters.CityID));

            if (!String.IsNullOrEmpty(filters.CityRegionID))
                customers = customers.Where(c => c.CityRegion.ID.ToString().Equals(filters.CityRegionID));

            if (!String.IsNullOrEmpty(filters.Gender))
            {
                var gender = Enum.Parse(typeof(Gender), filters.Gender);
                customers = customers.Where(c => c.Gender.ToString().Equals(gender.ToString()));
            }

            if (!String.IsNullOrEmpty(filters.LastPurchaseInitialDate))
            {
                var initialDate = DateTime.Parse(filters.LastPurchaseInitialDate);
                var finalDate = filters.LastPurchaseFinalDate.IsNullOrWhiteSpace() ? DateTime.Today : DateTime.Parse(filters.LastPurchaseFinalDate);
                customers = customers.Where(c => c.LastPurchase >= initialDate && c.LastPurchase <= finalDate);
            }

            if (!String.IsNullOrEmpty(filters.SellerID))
                customers = customers.Where(c => c.SellerID.ToString().Equals(filters.SellerID));

            var model = new CustomerListViewModel
            {
                Customers = customers.ToList(),
                Filters = filters
            };

            ViewBag.CustomerClassificationID = new SelectList(Db.CustomerClassifications, "ID", "Name");
            ViewBag.CityID = new SelectList(Db.Cities, "ID", "Name");
            ViewBag.CityRegionID = new SelectList(Db.CityRegions, "ID", "Name");
            if (User.IsInRole("Admin")) ViewBag.SellerID = new SelectList(Db.Users, "ID", "Email");

            return View("CustomerList", model);
        }