public Task <Unit> Handle(CreateFoodStoreCommand cmd, CancellationToken cancellationToken) { if (!cmd.IsValid()) { throw new Exception(); } var newItem = FoodStoreDomain.Create(cmd.Name, cmd.Link); var entity = _mapper.Map <FoodStore>(newItem); var entityId = _repo.Add(entity); if (_uow.Commit()) { _bus.RaiseEvent(new StoreCreatedEvent(newItem.Name, newItem.Link, entityId)); } return(Task.FromResult(new Unit())); }
public Task <Unit> Handle(DeleteFoodStoreCommand cmd, CancellationToken cancellationToken) { if (!cmd.IsValid()) { throw new Exception(); } var source = _foodStoreEventSourceManager.ReplayEntity(cmd.Id); var newItem = FoodStoreDomain.Delete(source); var entity = _mapper.Map <FoodStore>(newItem); entity.Id = cmd.Id; _repo.Update(entity); if (_uow.Commit()) { _bus.RaiseEvent(new StoreDeletedEvent(newItem.Name, newItem.Link, cmd.Id)); } return(Task.FromResult(new Unit())); }