Created
September 10, 2012 12:26
-
-
Save RemiBou/3690641 to your computer and use it in GitHub Desktop.
RemiDDD : Command Handler Sample
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 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