epr24pr5-ojanssen2/DelCommand.cpp

31 lines
794 B
C++

#include "DelCommand.h"
#include "Error.h"
#include "Manager.h"
using util::Util;
using util::Manager;
using err::Error;
namespace commands
{
DelCommand::DelCommand() : SubCommand("delete", 100, true)
{
}
void DelCommand::run(stringstream& args)
{
Manager& mgr = Manager::get_instance();
const string data_type = Util::read_string(args);
int id;
args >> id;
if (!args)
throw Error(102, "Ein Parameter eines Befehls konnte nicht gelesen werden");
if (data_type == "user")
mgr.del_user(id);
else if (data_type == "task")
mgr.del_task(id);
else
throw Error(102, "Ein Parameter eines Befehls konnte nicht gelesen werden");
mgr.save();
}
} // commands