c# - How to know if RESTful request didn't contain some arguments in ASP.Net Web API 2? -
i want client able sent info of model web via restful request. how can know if not part of object sent?
for example, request sent id, datetime_updated not qty , datetime_updated.
i know framework set value default of type, can check if datetime
wasn't sent (the default value 1/1/0001 12:00:00am have no meaning in application). int
, can't check if value 0 (0 has meaning).
// model namespace testingapi.models { public class operator { public int pkey { get; set; } public string id { get; set; } public int qty {get; set;} public datetime datetime_created { get; set; } public datetime datetime_updated { get; set; } } } // controller namespace testingapi.controllers { public class processingpalletcontroller : apicontroller { public dictionary<string, object> post(product datain) { // how can know if not argument in product sent? } } }
you can create optional members nullable:
namespace testingapi.models { public class operator { public int pkey { get; set; } public string id { get; set; } public int? qty {get; set;} public datetime datetime_created { get; set; } public datetime? datetime_updated { get; set; } } }
when consumer doesn't provide them, properties null.
c# asp.net asp.net-web-api asp.net-web-api2
No comments:
Post a Comment