/**
  * @param Market_OrderHistoryModel $model
  *
  * @return bool
  * @throws Exception
  * @throws \CDbException
  * @throws \Exception
  */
 public function save(Market_OrderHistoryModel $model)
 {
     if ($model->id) {
         $record = Market_OrderHistoryRecord::model()->findById($model->id);
         if (!$record) {
             throw new Exception(Craft::t('No order history exists with the ID “{id}”', ['id' => $model->id]));
         }
     } else {
         $record = new Market_OrderHistoryRecord();
     }
     $record->message = $model->message;
     $record->newStatusId = $model->newStatusId;
     $record->prevStatusId = $model->prevStatusId;
     $record->customerId = $model->customerId;
     $record->orderId = $model->orderId;
     $record->validate();
     $model->addErrors($record->getErrors());
     if (!$model->hasErrors()) {
         // Save it!
         $record->save(false);
         // Now that we have a record ID, save it on the model
         $model->id = $record->id;
         return true;
     } else {
         return false;
     }
 }