public ActionResult Filter(ClientViewModel clientViewModel)
        {
            ClientRN clientRN = new ClientRN();
            ViewBag.Clients = clientRN.FilterClients(clientViewModel);

            return View("List", clientViewModel);
        }
Exemple #2
0
        public List<ClientViewModel> FilterClients(ClientViewModel clientViewModel)
        {
            List<Client> clients = db.Client.ToList();

            clients = !String.IsNullOrEmpty(clientViewModel.Name) ? clients.Where(x => x.Name.Contains(clientViewModel.Name)).ToList() : clients;
            clients = !String.IsNullOrEmpty(clientViewModel.Gender) ? clients.Where(x => x.Gender == clientViewModel.Gender).ToList() : clients;
            clients = !String.IsNullOrEmpty(clientViewModel.City) ? clients.Where(x => x.Region.City.CityName == clientViewModel.City).ToList() : clients;
            clients = !String.IsNullOrEmpty(clientViewModel.RegionName) ? clients.Where(x => x.Region.RegionName == clientViewModel.RegionName).ToList() : clients;
            clients = !String.IsNullOrEmpty(clientViewModel.ClassificationName) ? clients.Where(x => x.Classification.ClassificationName == clientViewModel.ClassificationName).ToList() : clients;
            clients = clientViewModel.LastPurchaseSince.HasValue ? clients.Where(x => x.LastPurchase.Value >= clientViewModel.LastPurchaseSince.Value).ToList() : clients;
            clients = clientViewModel.LastPurchaseUntil.HasValue ? clients.Where(x => x.LastPurchase.Value <= clientViewModel.LastPurchaseUntil.Value).ToList() : clients;

            if (userRN.GetLoggedUser().Email != "*****@*****.**")
                clients = clients.Where(x => x.User.Email == userRN.GetLoggedUser().Email).ToList();

            return Mapper.Map<List<Client>, List<ClientViewModel>>(clients);
        }