我正在使用Corodva Contacts Plugin来获取本地手机联系人的工作效果很好,现在我需要将它与数据库进行比较,我不是使用本地数据库,我使用sql server 2012而且我已经编写了一些后端代码与WEBAPI.Its需要花费大量时间进行比较。我需要一些替代解决方案。请在下面建议我的代码。
//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)
{ }
}