public async Task Handle(RemovePartCommand command) { DomainModel.Part part = await _repository.GetAsync(command.Code); if (part == null) { return; } await _repository.RemoveAsync(part); }
public async Task Handle(AddPartCommand command) { if (await _dataAccessObject.AnyAsync(m => m.Code == command.Code)) { _logger.LogWarning("Part {code} already added", command.Code); await _bus.Publish(new PartAddedEvent { PartCode = command.Code }); return; } _logger.LogInformation("Add part with {code} requested by {user}", command.Code, _userAccessor.User?.Identity.Name); var part = new DomainModel.Part(command.Code, command.Name); await _repository.AddAsync(part); await _bus.Publish(new PartAddedEvent { PartCode = command.Code }); }