/// <summary>
        /// This function gets the clients and contacts for the given filters
        /// </summary>
        /// <param name="filters"></param>
        /// <returns></returns>
        public IEnumerable<ClientAndContact> GetClientsAndContacts(ClientContactFilter filters)
        {
            var parser = new FullTextQueryParser(true);
            filters.Keyword = parser.ParseQuery(filters.Keyword);

            var clientsAndContacts = new List<ClientAndContact>();
            // setup the parameters
            SqlParameter[] parameters = {
	                       new SqlParameter("@RecordsPerPage", filters.RecordsPerPage),
	                       new SqlParameter("@PageNo", filters.CurrentPage),
                           new SqlParameter("@ConsultantId", filters.ConsultantId),
                           new SqlParameter("@UserId", filters.UserId),
                           new SqlParameter("@ClientId", filters.ClientId ),
                           new SqlParameter("@ContactStatuses", filters.ContactStatusIds),
                           new SqlParameter("@ClientStatuses", filters.ClientStatusIds),
                           new SqlParameter("@Client", filters.Client),
                           new SqlParameter("@Forename", filters.Forename),
                           new SqlParameter("@Surname", filters.Surname),
                           new SqlParameter("@Email", filters.Email),
                           new SqlParameter("@JobTitle", filters.JobTitle),   
                           new SqlParameter("@Employer", filters.Employer),
	                       new SqlParameter("@Sectors", filters.Sectors),
	                       new SqlParameter("@LocationId", filters.Locations), 
                           new SqlParameter("@Qualifications", filters.Qualifications),
	                       new SqlParameter("@Skills", filters.Skills),
	                       new SqlParameter("@MinSalary", filters.MinSalary),
	                       new SqlParameter("@MaxSalary", filters.MaxSalary),
	                       new SqlParameter("@Keyword", filters.Keyword),
	                       new SqlParameter("@SortBy", filters.SortBy), 
	                       new SqlParameter("@Deleted" ,filters.Deleted),	
	                       new SqlParameter("@LastUpdatedDateFrom" ,filters.LastUpdatedDateFrom),
	                       new SqlParameter("@LastUpdatedDateTo", filters.LastUpdatedDateTo),
	                       new SqlParameter("@VacancyType" ,filters.VacancyType),
                           new SqlParameter("@GeneralCandidatesFolderId" ,filters.GeneralCandidatesFolderId), 
                           new SqlParameter("@Hours" ,filters.Hours), 
                           new SqlParameter("@GroupId" ,filters.GroupId),
                           new SqlParameter("@Miles" ,filters.LocationRadius),
	                       new SqlParameter("@RetrieveType",filters.RetrieveType)
            };
            // setup the connection
            var conn = new Sql_DataAccess(_connString);
            var ds = conn.GetDataSetFromSP("RetrieveClientContacts", parameters);
            // iterate and return clients
            if (ds != null && ds.Tables.Count > 0)
            {
                clientsAndContacts = (from DataRow dr in ds.Tables[0].Rows
                                      select ExtractClientContact(dr)).ToList();
            }
            return clientsAndContacts;
        }
        /// <summary>
        /// This function returns clients and contacts for top search
        /// </summary>
        /// <param name="filters"></param>
        /// <returns></returns>
        public IEnumerable<ClientAndContact> GetTopSearchResults(ClientContactFilter filters)
        {
            var clientsAndContacts = new List<ClientAndContact>();
            // setup the parameters
            SqlParameter[] parameters = {
	                       new SqlParameter("@RecordsPerPage", 25),
	                       new SqlParameter("@PageNo", filters.CurrentPage), 
	                       new SqlParameter("@Keyword", filters.Keyword)
            };
            // setup the connection
            var conn = new Sql_DataAccess(_connString);
            var ds = conn.GetDataSetFromSP("RetrieveTopSearchResults", parameters);
            // iterate and return clients
            if (ds != null && ds.Tables.Count > 0)
            {
                clientsAndContacts = (from DataRow dr in ds.Tables[0].Rows
                                      select ExtractClientContactTopSearch(dr)).ToList();
            }
            return clientsAndContacts;
        }
        /// <summary>
        /// This function get the selected contact/client objects for popup
        /// </summary> 
        /// <param name="selectedClientIds"></param>
        /// <param name="filters"></param>
        /// <param name="selectedContactIds"></param>
        /// <returns></returns>
        public IEnumerable<ContactClient> GetSelectedClientContactsForPoup(string selectedContactIds, string selectedClientIds, ClientContactFilter filters)
        {
            // init the response
            var result = new List<ContactClient>();

            // setup the parameters
            SqlParameter[] parameters;
            if (string.IsNullOrEmpty(selectedContactIds) && string.IsNullOrEmpty(selectedClientIds))
            {
                var parser = new FullTextQueryParser(true);
                filters.Keyword = parser.ParseQuery(filters.Keyword);

                parameters = new[] {
                           new SqlParameter("@RecordsPerPage", filters.RecordsPerPage),
	                       new SqlParameter("@PageNo", filters.CurrentPage),
                           new SqlParameter("@ConsultantId", filters.ConsultantId),
                           new SqlParameter("@UserId", filters.UserId),
                           new SqlParameter("@ClientId", filters.ClientId ),
                           new SqlParameter("@ContactStatuses", filters.ContactStatusIds),
                           new SqlParameter("@ClientStatuses", filters.ClientStatusIds),
                           new SqlParameter("@Client", filters.Client),
                           new SqlParameter("@Forename", filters.Forename),
                           new SqlParameter("@Surname", filters.Surname),
                           new SqlParameter("@Email", filters.Email),
                           new SqlParameter("@JobTitle", filters.JobTitle),   
                           new SqlParameter("@Employer", filters.Employer),
	                       new SqlParameter("@Sectors", filters.Sectors),
	                       new SqlParameter("@LocationId", filters.Locations), 
                           new SqlParameter("@Qualifications", filters.Qualifications),
	                       new SqlParameter("@Skills", filters.Skills),
	                       new SqlParameter("@MinSalary", filters.MinSalary),
	                       new SqlParameter("@MaxSalary", filters.MaxSalary),
	                       new SqlParameter("@Keyword", filters.Keyword),
	                       new SqlParameter("@SortBy", filters.SortBy), 
	                       new SqlParameter("@Deleted" ,filters.Deleted),	
	                       new SqlParameter("@LastUpdatedDateFrom" ,filters.LastUpdatedDateFrom),
	                       new SqlParameter("@LastUpdatedDateTo", filters.LastUpdatedDateTo),
	                       new SqlParameter("@VacancyType" ,filters.VacancyType),
                           new SqlParameter("@Hours" ,filters.Hours), 
                           new SqlParameter("@GroupId" ,filters.GroupId),
                           new SqlParameter("@Miles" ,filters.LocationRadius),
	                       new SqlParameter("@RetrieveType",filters.RetrieveType)
                            };
            }
            else
            {
                //assume that you dont use the filters, if you send the client ids or contacts ids 
                parameters = new[] { 
                           new SqlParameter("@RetrieveType",filters.RetrieveType),
	                       new SqlParameter("@CandidateIdsIn", string.IsNullOrEmpty(selectedContactIds) ? "" : selectedContactIds ), 
                           new SqlParameter("@ClientIdsIn", string.IsNullOrEmpty(selectedClientIds) ? "" : selectedClientIds )
                    };
            }


            // setup the connection
            var conn = new Sql_DataAccess(_connString);
            var ds = conn.GetDataSetFromSP("RetrieveClientContactsForPopup", parameters);
            // iterate and return clients
            if (ds != null && ds.Tables.Count > 0)
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    var obj = ExtractClientOrContact(dr);
                    var contact = obj as Candidate;
                    if (contact != null)
                        result.Add(new ContactClient
                        {
                            ClientOrContact = contact,
                            IsContact = true
                        });
                    else
                    {
                        //client found
                        var client = obj as Client;
                        if (client != null)
                            result.Add(new ContactClient
                            {
                                ClientOrContact = client,
                                IsContact = false
                            });
                    }
                }
            }
            return result;
        }
 public IEnumerable<ClientAndContact> GetClientsContactsPost(ClientContactFilter filters)
 {
     return new ClientsAndContacts().GetClientsAndContacts(filters);
 }