2017-03-22 28 views
0

我正在使用Corodva聯繫人插件來獲取本地電話聯繫人其工作很好,現在我需要與數據庫進行比較,我不使用本地數據庫,我正在使用SQL Server 2012和我使用WEBAPI編寫了一些後端代碼,它需要花費大量時間進行比較。我需要一些替代解決方案。請建議下面是我的代碼。最好的方式comapare與服務器的電話聯繫人

  //Javascript/// 

    var phoneNumberCollection = new Array(); 

    function showContacts() { 

var options = new ContactFindOptions(); 
    options.filter = ""; 
    options.multiple = true; 
    options.desiredFields = [navigator.contacts.fieldType.id,navigator.contacts.fieldType.displayName, navigator.contacts.fieldType.name, navigator.contacts.fieldType.phoneNumbers]; 
options.hasPhoneNumber = true; 
    var fields = [navigator.contacts.fieldType.displayName, navigator.contacts.fieldType.name]; 
    navigator.contacts.find(fields, onSuccess, onError, options); 
} 

function onSuccess(contacts) 
    { 
    // here i have all contacts and i am pushing each number into  "phoneNumberCollection" array// 
    } 

function onError(err) 
{ 
} 

    self.GetContactsData = function() { 
    self.PhoneNumberCollection = phoneNumberCollection; 
    jQuery.support.cors = true; 
    $.ajax({ 
     type: "POST", 
     dataType: "json", 
     contentType: 'application/json; charset=utf-8', 
     data: JSON.stringify({mobilecollection: self.PhoneNumberCollection,}), 
     url: Url + 'api/xxxxxx/xxxxxxxx', 
     success: function (data) { 
      self.items($.map(data, function (item) { 
       return new ContactsModel(item); 
      })); 
     }, 
     error: function (err, type, httpStatus) { 
     } 
    }) 

} 

    //Web API 
    [HttpPost] 
    public IHttpActionResult GetContacts(JObject jsonData) 
    { 
     try 
     { 
      if (jsonData != null) 
      { 
       dynamic json = jsonData; 

       string[] mobilenumberCollection = json.mobilecollection.ToObject<string[]>(); 
    //here i am getting Mobile collection and i am comparing each number with DB. i need some alternative sugggestion for this 
    var getContacts = CBFriends.getAllcontacts(mobilenumberCollection, deviceUID); 
       if (getAllContacts != null) 
       { 
        return Ok(getAllContacts); 
       } 
       else { return NotFound(); } 

      } 
      else { 
       return BadRequest();} 
      } 
     catch (Exception) 
     { }  
     } 
+0

這取決於很多參數,哪個字段只檢查DB中的ID或聯繫人中的所有字段? – Ygalbel

+0

@ybelbel感謝您的時間,我在我的數據庫中有一個名爲Mobile Number的列,所以我只需要檢查一列,我只比較本地電話號碼和數據庫手機號碼。 –

回答

0

在sql server中檢查IN運算符。

您可以在一個查詢中發送所有電話號碼,並獲取在db中不存在的電話號碼。

檢查this答案,看看如何在c#中實現這一點。

+0

感謝您的時間,我看到了,但我使用Linq來獲取數據,是否有任何使用Linq sql的例子 –

+0

檢查[這裏](http://stackoverflow.com/questions/2334327/what-is- -nql-in-operator) – Ygalbel

+0

var MobileNumberExsitDB = dbContext.UserTable.Where(m => m.mobileNumber == mobilenumber).FirstOrDefault();我正在使用像這樣的查詢,這將在foreach循環中包含一個數字在時間的移動號碼 –

相關問題