public async Task <Unit> Handle( PlaceOrder command, CancellationToken cancellationToken) { if (command.EventUserInfo == null) { throw new ApplicationException("User must be defined."); } var order = new Order(command.Id, command.OrderName, command.Items); var saved = await _repository.SaveOrder(command.EventUserInfo, order); if (!saved) { throw new ApplicationException("Failed to save."); } return(Unit.Value); }
public async Task <Unit> Handle( RemoveItemFromOrder command, CancellationToken cancellationToken) { if (command.EventUserInfo == null) { throw new ApplicationException("User must be defined."); } var order = await _repository.LoadOrder(command.Id); order.RemoveItem(command.Name); var saved = await _repository.SaveOrder(command.EventUserInfo, order); if (!saved) { throw new ApplicationException("Failed to save."); } return(Unit.Value); }