public IFactoryCommand CreateFactoryCommand(string databaseName) { switch (databaseName) { case "EFCore": var factoryContext = new FactoryContext(); var factoryCommand = new FactoryCommand(factoryContext); return(factoryCommand); default: throw new Exception("Error: Database engine not set in configuration file."); } }
/// <summary> /// Method to delete usersusing the Commands /// </summary> /// <param name="id">Id of the user</param> public void RemoveUser(string id) { try { Command <string, bool> CommandRemoveUser; CommandRemoveUser = FactoryCommand.GetCommandRemoveUser(); CommandRemoveUser.Execute(id); } catch (Exception e) { Command <Exception, bool> CommandCreateLog; CommandCreateLog = FactoryCommand.GetCommandCreateLog(); CommandCreateLog.Execute(e); } }
/// <summary> /// Method to update users using the Commands /// </summary> /// <param name="user">User to be updated</param> /// <returns>User</returns> public User UpdateUser(User user) { try { Command <Entity, Entity> CommandUpdateUser; CommandUpdateUser = FactoryCommand.GetCommandUpdateUser(); return((User)CommandUpdateUser.Execute(user)); } catch (Exception e) { Command <Exception, bool> CommandCreateLog; CommandCreateLog = FactoryCommand.GetCommandCreateLog(); CommandCreateLog.Execute(e); } return(null); }
/// <summary> /// Method to get one user using the Commands /// </summary> /// <param name="id">Id of the user</param> /// <returns>User</returns> public User GetUser(string id) { try { Command <string, Entity> CommandGetUser; CommandGetUser = FactoryCommand.GetCommandGetUser(); return((User)CommandGetUser.Execute(id)); } catch (Exception e) { Command <Exception, bool> CommandCreateLog; CommandCreateLog = FactoryCommand.GetCommandCreateLog(); CommandCreateLog.Execute(e); } return(null); }
/// <summary> /// Method to get all Users using the Commands /// </summary> /// <returns>List of user</returns>wfc public List <User> GetAll() { try { Command <bool, List <Entity> > CommandGetAll; CommandGetAll = FactoryCommand.GetCommandGetAll(); return(CommandGetAll.Execute(true).Cast <User>().ToList()); } catch (Exception e) { Command <Exception, bool> CommandCreateLog; CommandCreateLog = FactoryCommand.GetCommandCreateLog(); CommandCreateLog.Execute(e); } return(null); }
/// <summary> /// Execution of the Command /// </summary> /// <param name="param">Boolean</param> /// <returns>List of Users</returns> public override List <Entity> Execute(bool param) { string strClass = "CommandGetAll"; List <Entity> list = new List <Entity>(); try { IDaoUser daoUser = FactoryDao.GetDaoUser(); DataSet dsUser = daoUser.GetAll(); Command <DataSet, List <Entity> > commandConvertToJSON = FactoryCommand.GetCommandConvertUserIntoJSON(); list = commandConvertToJSON.Execute(dsUser); } catch (Exception e) { IDaoUser daoUser = FactoryDao.GetDaoUser(); daoUser.CreateLog(strClass, "There was a problem exectuting the command to get all users", true); throw new Exception("There was a problem exectuting the command to get all users", e); } return(list); }
/// <summary> /// Execution of the Command /// </summary> /// <param name="param">Id</param> /// <returns>User</returns> public override Entity Execute(string param) { string strClass = "CommandGetUser"; Entity user = FactoryEntity.GetUser(); try { IDaoUser daoUser = FactoryDao.GetDaoUser(); DataSet dsUser = daoUser.GetById(param); Command <DataSet, List <Entity> > commandConvertToJSON = FactoryCommand.GetCommandConvertUserIntoJSON(); user = commandConvertToJSON.Execute(dsUser)[0]; } catch (Exception e) { IDaoUser daoUser = FactoryDao.GetDaoUser(); daoUser.CreateLog(strClass, "There was a problem exectuting the command to get one user", true); throw new Exception("There was a problem exectuting the command to get one user", e); } return(user); }