public ActionResult CustomersList(ClientViewModel clientViewModel)
        {
            ClientModel clientModel = new ClientModel();
            var clients = clientModel.SearchClients(clientViewModel, GetCurrentUser());

            FillSearchFields();

            return View(clients);
        }
        public IEnumerable<ClientViewModel> SearchClients(ClientViewModel clientViewModel, User currentUser)
        {
            bool searchAllNames = string.IsNullOrWhiteSpace(clientViewModel.Name);
            bool searchAllGenders = string.IsNullOrWhiteSpace(clientViewModel.Gender);
            bool searchAllCities = clientViewModel.CityId == Guid.Empty;
            bool searchAllRegions = !clientViewModel.RegionId.HasValue
                                    || (clientViewModel.RegionId.HasValue && clientViewModel.RegionId.Value == Guid.Empty);
            bool searchAllClassifications = !clientViewModel.ClassificationId.HasValue
                                    || (clientViewModel.ClassificationId.HasValue && clientViewModel.ClassificationId.Value == Guid.Empty);
            bool searchAllSellers = clientViewModel.SellerId == Guid.Empty;
            bool searchAllLastPurchaseDates = !clientViewModel.LastPurchaseStartDate.HasValue && !clientViewModel.LastPurchaseEndDate.HasValue;

            var clients = from client in clientDal.GetAll()
                          where ((searchAllNames || client.Name == clientViewModel.Name)
                              && (searchAllGenders || client.Gender == clientViewModel.Gender)
                              && (searchAllCities || client.Region.CityId == clientViewModel.CityId)
                              && (searchAllRegions || client.Region.RegionId == clientViewModel.RegionId)
                              && (searchAllClassifications || (client.ClassificationId.HasValue && client.ClassificationId == clientViewModel.ClassificationId))
                              && (searchAllSellers || client.SellerId == clientViewModel.SellerId)
                              && (searchAllLastPurchaseDates ||
                                  (
                                        (clientViewModel.LastPurchaseStartDate.HasValue && !clientViewModel.LastPurchaseEndDate.HasValue
                                            && client.LastPurchase >= clientViewModel.LastPurchaseStartDate.Value)
                                    || (!clientViewModel.LastPurchaseStartDate.HasValue && clientViewModel.LastPurchaseEndDate.HasValue
                                            && client.LastPurchase <= clientViewModel.LastPurchaseEndDate.Value)
                                    || (client.LastPurchase >= clientViewModel.LastPurchaseStartDate.Value
                                            && client.LastPurchase <= clientViewModel.LastPurchaseEndDate.Value)
                                  )
                                )
                              && ((currentUser.IsAdmin.HasValue && currentUser.IsAdmin.Value == true)
                                    || (client.User.UserId == currentUser.UserId))
                                )
                          select client;

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