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
namespace SimpleCQRS | |
{ | |
public class InventoryCommandHandlers | |
{ | |
private readonly IRepository<InventoryItem> _repository; | |
public InventoryCommandHandlers(IRepository<InventoryItem> repository) | |
{ | |
_repository = repository; | |
} | |
public void Handle(CreateInventoryItem message) | |
{ | |
var item = new InventoryItem(message.InventoryItemId, message.Name); | |
_repository.Save(item, -1); | |
} | |
public void Handle(DeactivateInventoryItem message) | |
{ | |
var item = _repository.GetById(message.InventoryItemId); | |
item.Deactivate(); | |
_repository.Save(item, message.OriginalVersion); | |
} | |
public void Handle(RemoveItemsFromInventory message) | |
{ | |
var item = _repository.GetById(message.InventoryItemId); | |
item.Remove(message.Count); | |
_repository.Save(item, message.OriginalVersion); | |
} | |
public void Handle(CheckInItemsToInventory message) | |
{ | |
var item = _repository.GetById(message.InventoryItemId); | |
item.CheckIn(message.Count); | |
_repository.Save(item, message.OriginalVersion); | |
} | |
public void Handle(RenameInventoryItem message) | |
{ | |
var item = _repository.GetById(message.InventoryItemId); | |
item.ChangeName(message.NewName); | |
_repository.Save(item, message.OriginalVersion); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment