I have a PATCH endpoint in controller with method taking EditGroupApiCommand
as parameter:
In Swagger you can provide a JSON object with those parameters as such:
Regardless if the Manager
property has been included in JSON and set to null or it was omitted,
In the controller I am receiving an empty guid.
I want to distinguish two cases:
- Manager guid has been omitted (then I skip any validation/actions)
- Manager guid has been explicitly set to null (I remove the managers)
CodePudding user response:
Your Manager
property is a Guid
which means it can not be null.
When the value is missing in the incoming data it will result in default(Guid)
, same happens if it is set to null
.
If you can change the EditGroupApiCommand
, change the public Guid Manager
to public Guid? Manager
.
If you want to delete the Manager
=> set the Manager to Guid.Empty
:
{
"Manager": "00000000-0000-0000-0000-000000000000"
}
If it was ommited => it is null.
So you have to explicitly set it to Guid.Empty
to distinguish thge use cases.