void PhoneModel::editPhone(int contractorId, Phone newPhone) { query = new QSqlQuery(Database::getInstance().db); query->prepare("UPDATE contractors_phones SET phone_name = ?, number = ?, is_default = ? " "WHERE contractors_phones.id_contractors_phone = ? and contractor = ?"); query->addBindValue(newPhone.getName()); query->addBindValue(newPhone.getNumber()); query->addBindValue(QVariant(newPhone.isDefault()).toInt()); query->addBindValue(newPhone.getId()); query->addBindValue(contractorId); query->exec(); if(this->isQueryError(query)) throw new SQLException("PhoneModel::editPhone", query); delete query; }
void PhoneModel::addPhone(int contractorId, Phone phone) { if(phone.getName().isEmpty()) phone.setName("."); if(phone.getNumber().isEmpty()) phone.setNumber("."); query = new QSqlQuery(Database::getInstance().db); query->prepare("INSERT INTO contractors_phones (contractor, phone_name, number, is_default) " "VALUES (?, ?, ?, ?)"); query->addBindValue(contractorId); query->addBindValue(phone.getName()); query->addBindValue(phone.getNumber()); query->addBindValue(QVariant(phone.isDefault()).toInt()); query->exec(); if(this->isQueryError(query)) throw new SQLException("PhoneModel::addPhone", query); delete query; }