void MoFileRepo::updateDesc(string title, string desc) throw (RepositoryException) { vector<Movie*> allMovies = findAll(); unsigned i = 0; while(i < allMovies.size() && allMovies[i]->getTitle().compare(title) != 0) i++; if (i == allMovies.size()) { for(unsigned j = 0; j < allMovies.size(); j++) delete allMovies[j]; throw RepositoryException("There is no artist with this name!"); } allMovies[i]->setDesc(desc); ofstream out; out.open(fileName,ios::trunc); if(!out.is_open()) cout << "Failed to open artists file!updateDesc"<<fileName<<endl; else { for(unsigned j = 0; j < allMovies.size(); j++) { out << allMovies[j]->getTitle() << endl << allMovies[j]->getType() << endl<< allMovies[j]->getDesc() << endl<< allMovies[j]->getAvailable() << endl; delete allMovies[j]; } out.close(); } }
void ClInMemRepo::updateNoRentedMovies(string cnp, int newNo) throw (RepositoryException) { Client* c = findCnp(cnp); if (c == NULL) throw RepositoryException("There is no client with the specified cnp!"); c->setNoRentedMovies(newNo); }
void ClInMemRepo::updateName(string cnp, string newName) throw (RepositoryException) { Client* c = findCnp(cnp); if (c == NULL) throw RepositoryException("There is no client with the specified cnp!"); c->setName(newName); }
void ClInMemRepo::save(Client client) throw (RepositoryException) { Client* c = findCnp(client.getCnp()); if(c == NULL) clients.push_back(new Client(client)); else throw RepositoryException("There is a client with this cnp!"); }
void Controller::add(const Expense& e) throw (RepositoryException){ try { this->val.validate(e); this->repo->add(e); } catch (RepositoryException &s){ throw RepositoryException(s.getMsg()); } }
void Controller::update(const int id,Expense& e) throw (RepositoryException){ try{ this->val.validate(e); this->repo->update(id,e); } catch (RepositoryException &s){ throw RepositoryException(s.getMsg()); } }
void FilmCart::del(const std::string& title) { auto filmIt = std::find_if(this->__movies.begin(), this->__movies.end(), [&](const Film& film) {return film.getTitle() == title; }); if (filmIt == this->__movies.end()) { //qDebug() << film.getTitle().c_str() << film.getGen().c_str() << film.getReleaseYear() << film.getMainActor().c_str() << "'\n"; throw RepositoryException("Error in cart: trying to delete unexistent film!"); } this->__movies.erase(filmIt); }
void MemRepository::add(const Expense& e) throw (RepositoryException){ Expense* e1 = this->findById(e.getId()); if (e1 == NULL){ e1 = new Expense(e); this->repo.push_back(e1); } else throw RepositoryException("Duplicated id!\n"); }
void ClInMemRepo::removeByCnp(string cnp) throw (RepositoryException) { unsigned i = 0; while(i < clients.size() && clients[i]->getCnp().compare(cnp) != 0) i++; if(i < clients.size()) clients.erase(clients.begin() + i); else throw RepositoryException("There is no client with this cnp!"); }
void MemRepository::remove(const int id) throw (RepositoryException){ Expense* e1; for (unsigned i = 0; i < this->repo.size(); i++){ e1 = this->repo.at(i); if(e1->getId() == id){ this->repo.erase(this->repo.begin()+i); return; } } throw RepositoryException("No Expense with this id!\n"); }
void MemRepository::update(const int id, Expense& e1) throw (RepositoryException){ Expense* e; Expense* e2 = new Expense(e1); for (unsigned i = 0; i < this->repo.size(); i++){ e = this->repo.at(i); if(e->getId() == id){ this->repo.at(i) = e2; return; } } throw RepositoryException("No Expense with this id!\n"); }
void MoFileRepo::save(Movie m) throw (RepositoryException) { Movie* pm = findByTitle(m.getTitle()); if (pm != NULL) { delete pm; throw RepositoryException("There is already a movie with this title!"); } ofstream out; out.open(fileName,ios::app); if(!out.is_open()) cout << "Failed to open movies file!save()"<<fileName<<endl; else { out << m.getTitle() << "\n" << m.getType() << "\n" << m.getDesc() << "\n"<< m.getAvailable() <<"\n"; out.close(); } }