I am trying to implement this Command Pattern in my .NET MVC 3 application, in particular, to save changes to Thing. I do not know how to do that. Before moving on to the current issue, here is a simplified code:
public class ThingController
{
private readonly ICommandHandler<EditThingCommand> handler;
public ThingController(ICommandHandler<EditThingCommand> handler)
{
this.handler = handler;
}
public ActionMethod EditThing(int id)
{
...build EditThingViewModel and return with View...
}
[HttpPost]
public ActionMethod EditThing(int id, EditThingViewModel vm)
{
var command = new EditThingCommand
{
...not sure yet...
};
this.handler.Handle(command);
...redirect somewhere...
}
}
My EditThingViewModel is completely disconnected from my domain, which consists of POCO classes. It seems that my EditThingCommand should look like this:
public class EditThingCommand
{
Thing ModifiedThing;
}
However, ModifiedThing will still be in the Mod controller. This is most of the work in this case. By the time ModifiedThing was created (and the "old" timestamp applied to it to verify concurrency optimism), all that was left was a command to invoke "Refresh" in my data context.
, , ModifiedThing . (, .) EditThingCommand EditThingViewModel, . poco?