1.测试DataSourceLoadOptions 类 在postman中如何测试
在Query Params
中填值
KEY VALUE
companyId 1
也可以是 Body 中的 raw输入 参数 格式是JSON格式
{
"companyId":1
}
地址:http://localhost:8081/Base/GetFleetDropdown?companyId=1
[HttpGet]
[Route("GetFleetDropdown")]
public HttpResponseMessage GetFleetDropdown(DataSourceLoadOptions loadOptions)
{
try
{
var queryParams = Request.GetQueryNameValuePairs().ToDictionary(x => x.Key, x => x.Value);
if (queryParams.ContainsKey("companyId"))
{
int companyId = Convert.ToInt32(queryParams["companyId"]);
loadOptions.PrimaryKey = new[] { "FleetId" };
loadOptions.DefaultSort = "FleetName";
var fleetDropdown = dropdownBuilders.BuildFleetDropdownList(companyId);
return Request.CreateResponse(DataSourceLoader.Load(fleetDropdown, loadOptions));
}
else
{
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "No companyId");
}
}
catch(Exception ex)
{
return Request.CreateErrorResponse(HttpStatusCode.ExpectationFailed, ex.Message);
}
}
2.测试[FromBody]JObject 参数 在 Body中测试 放入参数
{
"Key": "abc",
"Values": {
"carId": 8,
"startTime": "2019-12-01 12:00:00",
"endTime": "2019-12-01 19:00:00"
}
}
地址:http://localhost:8081/History/GetCarHistory
[HttpPost]
[Route("GetCarHistory")]
public HttpResponseMessage GetCarHistory([FromBody]JObject jsonObject)
{
ApiResponse response = new ApiResponse();
try
{
string key = jsonObject["Key"].ToString();
JObject values = JObject.Parse(jsonObject["Values"].ToString());
int carId = Convert.ToInt32(values["carId"]);
DateTime startTime = Convert.ToDateTime(values["startTime"]);
DateTime endTime = Convert.ToDateTime(values["endTime"]);
DateTime sss = Convert.ToDateTime("2019-10-20 15:00:00");
//var aaaa = (int)(sss - TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1))).TotalSeconds;
//var bbbb = (sss.ToUniversalTime().Ticks - 621355968000000000) / 10000000;
response.ResultStr = gridBuilders.BuildCarHistoryGrid2(carId, startTime, endTime);
response.ResultCode = ApiResultCode.OK;
}
catch(Exception ex)
{
response.ResultCode = ApiResultCode.NG;
response.ErrorMsg = ex.Message;
}
return new HttpResponseMessage()
{
Content = new StringContent(JsonConvert.SerializeObject(response, serializerSettings.Settings()), Encoding.UTF8, "application/json"),
};
}