コード例 #1
0
 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());
     }
 }
コード例 #2
0
        public IActionResult Post([FromBody] CustomerRecord customer)
        {
            CustomerRecord created = _sqliteRepository.Create(customer);

            return(CreatedAtRoute("GetCustomer", new { id = created.Id }, created));
        }