void CrudController<ControllerClass, MapperClass>::save() { Identity id = m_parameters["id"].value<Identity>(); Model * model = nullptr; QVariantMap record; if (getDataMapper().isValidId(id)) { model = getDataMapper().get(id); } else { model = getDataMapper().newModel(); } for (const QString & key : getDataMapper().selectVariables()) { if (m_parameters.contains(key)) { record[key] = m_parameters[key].asQVariant(); } } if (model) { getDataMapper().buildFromRecord(model, record); beforeSave(model); getDataMapper().save(model); } redirect(url(&ControllerClass::index)); }
bool BaseFile::saveAs(const std::string & name) { std::string s = name; if(s == "") { s = chooseSaveFileName(); if(s == "") return false; } beforeSave(); if(!doWrite(s)) return false; setFileName(s); setClean(); return true; }
bool BaseFile::save() { if(!shouldSave()) return false; if(isUntitled()) { std::string s = chooseSaveFileName(); if(s == "") return false; return saveAs(s); } beforeSave(); if(!doWrite(fileName())) return false; setClean(); return true; }