RESTful API メソッドを作成しようとしています。しかし、期待どおりに機能していません。
コードはそれ自体を物語っています。完全な方法は次のとおりです。
public CustomResult Query(
int? count,
string os = null,
string manufacturer = null,
string has_camera = null,
string has_gprs = null,
string has_wifi = null,
string has_edge = null,
string has_bluetooth = null,
string has_gpu = null,
string has_gps = null,
string has_radio = null
)
{
TimeSpan T = DateTime.Now.TimeOfDay;
Result result = new Result();
List<Mobile> MbList = getMobileList();
if (os != null)
{
MbList = (from M in MbList
where (M.Feature.OS.ToLower().IndexOf(os.ToLower()) >= 0)
select M).ToList();
}
if (manufacturer != null)
{
MbList = (from M in MbList
where (M.Manufacturer.ToLower() == manufacturer.ToLower())
select M).ToList();
}
#region Camera Check
if (has_camera != null)
{
if (has_camera == "true")
{
MbList = (from M in MbList
where (M.Camera.Primary.ToLower() != "n/a" || M.Camera.Primary.ToLower() != "no")
select M).ToList();
}
else
{
MbList = (from M in MbList
where (M.Camera.Primary.ToLower() == "n/a" || M.Camera.Primary.ToLower() == "no")
select M).ToList();
}
}
#endregion
#region GPRS Check
if (has_gprs != null)
{
if (has_gprs == "true")
{
MbList = (from M in MbList
where (M.Data.GPRS.ToLower() != "n/a" || M.Data.GPRS.ToLower() != "no")
select M).ToList();
}
else
{
MbList = (from M in MbList
where (M.Data.GPRS.ToLower() == "n/a" || M.Data.GPRS.ToLower() != "no")
select M).ToList();
}
}
#endregion
#region Wifi Check
if (has_wifi != null)
{
if (has_wifi == "true")
{
MbList = (from M in MbList
where (M.Data.WAN.ToLower() != "n/a" || M.Data.WAN.ToLower() != "no")
select M).ToList();
}
else
{
MbList = (from M in MbList
where (M.Data.WAN.ToLower() == "n/a" || M.Data.WAN.ToLower() == "no")
select M).ToList();
}
}
#endregion
#region GPU Check
if (has_gpu != null)
{
if (has_gpu.ToLower().CompareTo("true") > 0)
{
MbList = (from M in MbList
where (M.Feature.GPU.ToLower() != "n/a" || M.Feature.GPU.ToLower() != "no")
select M).ToList();
}
else
{
MbList = (from M in MbList
where (M.Feature.GPU.ToLower() == "n/a" || M.Feature.GPU.ToLower() == "no")
select M).ToList();
}
}
#endregion
#region EDGE Check
if (has_edge != null)
{
if (has_edge == "true")
{
MbList = (from M in MbList
where (M.Data.EDGE.ToLower() != "n/a" || M.Data.EDGE.ToLower() != "no")
select M).ToList();
}
else
{
MbList = (from M in MbList
where (M.Data.EDGE.ToLower() == "n/a" || M.Data.EDGE.ToLower() == "no")
select M).ToList();
}
}
#endregion
#region Bluetooth Check
if (has_bluetooth != null)
{
if (has_bluetooth == "true")
{
MbList = (from M in MbList
where (M.Data.Bluetooth.ToLower() != "n/a" || M.Data.Bluetooth.ToLower() != "no")
select M).ToList();
}
else
{
MbList = (from M in MbList
where (M.Data.Bluetooth.ToLower() == "n/a" || M.Data.Bluetooth.ToLower() == "no")
select M).ToList();
}
}
#endregion
#region GPS Check
if (has_gps != null)
{
if (has_gps == "true")
{
MbList = (from M in MbList
where (M.Feature.GPS.ToLower() != "n/a" || M.Feature.GPS.ToLower() != "no")
select M).ToList();
}
else
{
MbList = (from M in MbList
where (M.Feature.GPS.ToLower() == "n/a" || M.Feature.GPS.ToLower() == "no")
select M).ToList();
}
}
#endregion
#region Radio Check
if (has_radio != null)
{
if (has_radio == "true")
{
MbList = (from M in MbList
where (M.Feature.Radio.ToLower() != "n/a" || M.Feature.Radio.ToLower() != "no")
select M).ToList();
}
else
{
MbList = (from M in MbList
where (M.Feature.Radio.ToLower() == "n/a" || M.Feature.Radio.ToLower() == "no")
select M).ToList();
}
}
#endregion
if (count.HasValue)
{
MbList = MbList.Take(count.Value).ToList<Mobile>();
}
result.Count = MbList.Count;
result.Data = MbList;
result.TimeElapsed = getElapsedTiming(T);
return new CustomResult() { R = result };
}
問題は、has_camera またはその他の「has」パラメーターを「true」に渡すと、すべてのレコードが返されることです。パラメータに「false」を渡すと、メソッドは正しく機能します。
PS誰かがこれを行うためのより良い方法を提案してくれたら、私は感謝します. はい、私のコードは幼稚です。申し訳ありません。
ありがとう。