protected override void Execute()
 {
     Logger.Current.Informational("Entering into SmartSearchProcessor");
     try
     {
         List <int>            contactIds        = null;
         Dictionary <int, int> searchDefinitions = advancedSearchRepository.GetAllSearchDefinitionIsAndAccountIds();
         foreach (var data in searchDefinitions)
         {
             try
             {
                 GetSavedSearchContactIdsRequest advRequest = new GetSavedSearchContactIdsRequest()
                 {
                     SearchDefinitionId = data.Key,
                     AccountId          = data.Value
                 };
                 var task = Task.Run(() => advancedSearchService.GetSavedSearchContactIds(advRequest));
                 contactIds = task.Result;
                 List <SmartSearchContact> savedSearchContacts = new List <SmartSearchContact>();
                 foreach (int contactId in contactIds)
                 {
                     SmartSearchContact savedSearchcontact = new SmartSearchContact();
                     savedSearchcontact.SearchDefinitionID = data.Key;
                     savedSearchcontact.ContactID          = contactId;
                     savedSearchcontact.AccountID          = data.Value;
                     savedSearchcontact.IsActive           = true;
                     savedSearchContacts.Add(savedSearchcontact);
                 }
                 contactRepository.DeleteSavedSearchContactsBySearchDefinitionId(data.Key, data.Value);
                 contactRepository.InsertBulkSavedSearchesContacts(savedSearchContacts);
                 advancedSearchRepository.UpdateSmartSearchQueue(data.Key, data.Value, true);
             }
             catch (Exception ex)
             {
                 Logger.Current.Error(string.Format("Couldn't not fetch data for Smart Search {0} , Account {1}", data.Key, data.Value), ex);
                 advancedSearchRepository.UpdateSmartSearchQueue(data.Key, data.Value, true);
             }
         }
     }
     catch (Exception ex)
     {
         Logger.Current.Error("Error while Smart Search Contacts Processing", ex);
     }
 }
        protected override void ExecuteInternal(IJobExecutionContext context)
        {
            Log.Informational("Entering into SmartSearchProcessor");
            var searchDefinitions = _advancedSearchRepository.GetAllSearchDefinitionIsAndAccountIds();

            foreach (var seachDefinition in searchDefinitions)
            {
                try
                {
                    var advRequest = new GetSavedSearchContactIdsRequest
                    {
                        SearchDefinitionId = seachDefinition.Key,
                        AccountId          = seachDefinition.Value
                    };
                    var contactIds          = _advancedSearchService.GetSavedSearchContactIds(advRequest).Result;
                    var savedSearchContacts = new List <SmartSearchContact>();
                    foreach (var contactId in contactIds)
                    {
                        var savedSearchcontact = new SmartSearchContact
                        {
                            SearchDefinitionID = seachDefinition.Key,
                            ContactID          = contactId,
                            AccountID          = seachDefinition.Value,
                            IsActive           = true
                        };
                        savedSearchContacts.Add(savedSearchcontact);
                    }
                    _contactRepository.DeleteSavedSearchContactsBySearchDefinitionId(seachDefinition.Key, seachDefinition.Value);
                    _contactRepository.InsertBulkSavedSearchesContacts(savedSearchContacts);
                    _advancedSearchRepository.UpdateSmartSearchQueue(seachDefinition.Key, seachDefinition.Value, true);
                }
                catch (Exception ex)
                {
                    Log.Error($"Couldn't not fetch data for Smart Search {seachDefinition.Key} , Account {seachDefinition.Value}", ex);
                    _advancedSearchRepository.UpdateSmartSearchQueue(seachDefinition.Key, seachDefinition.Value, true);
                }
            }
        }