示例#1
0
        public IActionResult Put(long id, [FromBody] CustomerRecord customer)
        {
            var record = _sqliteRepository.GetById(id);

            if (record == null)
            {
                return(NotFound());
            }
            customer.Id = id;
            _sqliteRepository.Update(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());
     }
 }