Created
August 6, 2016 12:26
-
-
Save stefc/66b43041394688ef447bec99cde870a9 to your computer and use it in GitHub Desktop.
NancyFX ModelBinding Example
This file contains 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
public class AufnehmenAufgabe : IDomainCommand { | |
public Guid Id { get; } | |
public string Titel { get; } | |
public AufnehmenAufgabe(Guid id, string titel) | |
{ | |
Id = id; | |
Titel = titel; | |
} | |
} | |
public class AendernAufgabenTitel : IDomainCommand { | |
public Guid Id { get; } | |
public string Titel { get; } | |
public AendernAufgabenTitel(Guid id, string titel) | |
{ | |
Id = id; | |
Titel = titel; | |
} | |
} | |
public class EntfernenAufgabe : IDomainCommand { | |
public Guid Id { get; } | |
public EntfernenAufgabe(Guid id) | |
{ | |
Id = id; | |
} | |
} |
This file contains 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
// Update Command's | |
Put("/{id}", args => { | |
var id = Guid.Parse(args.id); | |
var domainModel = DomainModel; | |
if (domainModel.Equals(nameof(AendernAufgabenTitel))) { | |
var token = JObject.Parse(Request.Body.AsString())?.Root; | |
var titel = token.Value<string>(nameof(AendernAufgabenTitel.Titel)); | |
var cmd = new AendernAufgabenTitel(id, titel); | |
return true; | |
} | |
else if (domainModel.Equals(nameof(ErledigenAufgabe))) { | |
var cmd = new ErledigenAufgabe(id); | |
return true; | |
} | |
else if (domainModel.Equals(nameof(WiedervorlegenAufgabe))) { | |
var cmd = new WiedervorlegenAufgabe(id); | |
return true; | |
} | |
return CommandNotAccepted; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I would be happy if I can Bind it easy with NancyFx. For example the parameter naming of the ctor can be named like the args.id or body.titel stuff.
this.Bind<AendernAufgabenTitel>( (id,titel) => new AendernAufgabenTitel(id,title))
The above work fine but if I can delegate that binding to NancyFx it would be even finer.