public function actionDeleteRecipientList()
 {
     $this->requirePostRequest();
     $id = craft()->request->getRequiredPost('id');
     $model = null;
     if ($model = sproutEmailDefaultMailer()->getRecipientListById($id)) {
         if (!$model) {
             throw new Exception(Craft::t('Recipient list with id ({id}) was not found.', array('id' => $id)));
         }
         $vars = array('recipientListId' => $model->id);
         $deleted = SproutEmail_DefaultMailerRecipientListRecord::model()->deleteByPk($model->id);
         if ($deleted) {
             SproutEmail_DefaultMailerRecipientListRecipientRecord::model()->deleteAllByAttributes($vars);
             craft()->userSession->setNotice(Craft::t('Recipient list deleted successfully.'));
             if (craft()->request->isAjaxRequest()) {
                 $this->returnJson(array('success' => true));
             }
         } else {
             craft()->userSession->setNotice(Craft::t('Unable to delete recipient list.'));
             if (craft()->request->isAjaxRequest()) {
                 $this->returnErrorJson(Craft::t('Unable to delete recipient list.'));
             }
         }
         $this->redirectToPostedUrl($model);
     }
     throw new HttpException(404);
 }
 public function saveRecipientList(SproutEmail_DefaultMailerRecipientListModel &$model)
 {
     if (isset($model->id) && is_numeric($model->id)) {
         $record = SproutEmail_DefaultMailerRecipientListRecord::model()->findById($model->id);
         if ($record) {
             $record->setAttributes($model->getAttributes(), false);
         }
     } else {
         $record = new SproutEmail_DefaultMailerRecipientListRecord();
         $record->name = $model->name;
         $record->handle = $model->handle;
         $record->dynamic = (int) $model->dynamic;
     }
     if ($record->validate()) {
         try {
             $record->save(false);
             $model->id = $record->id;
             return true;
         } catch (\Exception $e) {
             $model->addError('save', $e->getMessage());
         }
     } else {
         $model->addErrors($record->getErrors());
     }
     return false;
 }