Last active
March 7, 2019 07:30
-
-
Save anthonydotnet/dff6440ae77129a803dc711de8747bc2 to your computer and use it in GitHub Desktop.
Crud response with Typed entity in CreateAsync so you don't have to cast the entity later
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This wouldn't work in my code, because ICrudResponse doesnt have Entity as a property. So it still requires casting. | |
ICrudResponse response; | |
// create 1 | |
response = service.CreateAsync<Profile>(poco1).Result; | |
System.Console.WriteLine($"CreateAsync. {response.StatusCode}"); | |
if (response.StatusCode == StatusCode.Created) | |
{ | |
var entity = response.Entity; // This Entity prorperty doesn't exist in ICrudResponse so still won't build | |
System.Console.WriteLine($"Success - Id {entity.Id}"); | |
} | |
else if (response.StatusCode == StatusCode.Conflict) | |
{ | |
var castedConflictResult = response as ConflictResponse; | |
System.Console.WriteLine($"Conflicted. Id {castedConflictResult.Id}"); | |
} | |
else | |
{ | |
var castedErrorResult = response as ErrorResponse; | |
System.Console.WriteLine($"Server error. Id {castedErrorResult.Message}"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment