Skip to content

Instantly share code, notes, and snippets.

@RemiBou
Created September 10, 2012 12:26
Show Gist options
  • Save RemiBou/3690641 to your computer and use it in GitHub Desktop.
Save RemiBou/3690641 to your computer and use it in GitHub Desktop.
RemiDDD : Command Handler Sample
public class SelectProductCommandHandler : ICommandHandler<SellProductCommand>
{
private readonly DbContext _dbcontext;
public SelectProductCommandHandler(DbContext dbcontext)
{
_dbcontext = dbcontext;
}
public void Execute(SellProductCommand command)
{
Product product = _dbcontext.Set<Product>().Single(p => p.Id == command.ProductId);//load the
var order = new Order()
{
CustomerId = command.CustomerId,
ProductId = command.ProductId,
Comment = command.SellerComment,
Price = product.Price
};
_dbcontext.Set<Order>().Add(order);
_dbcontext.SaveChanges();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment