epr24pr5-ojanssen2/AddCommand.cpp

38 lines
809 B
C++
Raw Normal View History

#include "AddCommand.h"
#include "Error.h"
#include "Manager.h"
using util::Manager;
using util::Util;
using models::AddUser;
using models::AddTask;
using err::Error;
namespace commands
{
AddCommand::AddCommand() : SubCommand("add", 100, true)
{
}
void AddCommand::run(stringstream& args)
{
const string data_type = Util::read_string(args);
Manager& mgr = Manager::get_instance();
if (data_type == "user")
{
AddUser u;
args >> u;
mgr.add_user(new User(u));
}
else if (data_type == "task")
{
AddTask t;
args >> t;
mgr.add_task(new Task(t));
}
else
throw Error(101, "Befehl ist unbekannt.");
mgr.save();
}
} // commands