public IActionResult GetById(long id) { var customer = _sqliteRepository.GetById(id); if (customer == null) { return(NotFound()); } return(new ObjectResult(customer)); }
public IActionResult Put(long id, [FromBody] UpdateCustomerCommand customer) { var record = _sqliteRepository.GetById(id); if (record == null) { return(NotFound()); } customer.Id = id; _commandHandler.Execute(customer); return(NoContent()); }
public void Execute(Command command) { if (command == null) { throw new ArgumentNullException("command is null"); } if (command is CreateCustomerCommand createCommand) { CustomerRecord created = _repository.Create(createCommand.ToCustomerRecord()); _eventPublisher.PublishEvent(createCommand.ToCustomerEvent(created.Id)); } else if (command is UpdateCustomerCommand updateCommand) { CustomerRecord record = _repository.GetById(updateCommand.Id); _repository.Update(updateCommand.ToCustomerRecord(record)); _eventPublisher.PublishEvent(updateCommand.ToCustomerEvent()); } else if (command is DeleteCustomerCommand deleteCommand) { _repository.Remove(deleteCommand.Id); _eventPublisher.PublishEvent(deleteCommand.ToCustomerEvent()); } }