【发布时间】:2017-08-14 17:24:56
【问题描述】:
我正在使用 Corodva 联系人插件来获取本地电话联系人,它工作得很好,现在我需要将它与数据库进行比较,我没有使用本地数据库,我使用的是 sql server 2012,并且我已经编写了一些后端代码与 WEBAPI.It 花费大量时间进行比较。我需要一些替代解决方案。请建议以下是我的代码。
//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)
{ }
}
【问题讨论】:
-
这取决于许多参数,您在数据库中仅检查 id 或联系人中的所有字段中的哪个字段?
-
@ygalbel 感谢您抽出宝贵时间,我的数据库中有名为“手机号码”的列,所以我只需要检查一列,我只将本地电话号码与数据库手机号码进行比较,请建议。跨度>
标签: c# asp.net-web-api asp.net-web-api2 cordova-plugins