/// <summary> /// Get list of available projects for specified application. /// </summary> /// <param name="appcode">string: Application code.</param> /// <returns>System.Collections.Generic.List<string></returns> internal List<string> GetProjectsByApp(string appcode) { List<string> results = new List<string>(); // Check argument to make sure a value was passed if (appcode.Length == 0) throw new System.ArgumentException("You must specify a valid application code in argument."); // Create database objects Data.ProjectsDs.ProjectsDataTable projectTable = new ProjectsDs.ProjectsDataTable(); Data.ProjectsDsTableAdapters.ProjectsTableAdapter tableAdapter = new iCampaign.TACS.Data.ProjectsDsTableAdapters.ProjectsTableAdapter(); tableAdapter.Connection = new SqlConnection(TacsSession.ConnectionString); // Query the database try { tableAdapter.Connection.Open(); tableAdapter.FillByApp(projectTable, appcode); } catch (Exception ex) { throw ex; } finally { tableAdapter.Connection.Close(); } // Transfer database results to the list collection foreach (Data.ProjectsDs.ProjectsRow row in projectTable) { results.Add(row.Project); } return results; }
/// <summary> /// Retrieves a data table containing the projects under the specified account id. /// </summary> /// <param name="acctId">long: Account id.</param> /// <returns>iCampaign.TACS.Data.ProjectDs.ProjectsDataTable</returns> internal iCampaign.TACS.Data.ProjectsDs.ProjectsDataTable GetProjects(long acctId) { // Instantiate the database objects ProjectsDs.ProjectsDataTable dataTable = new ProjectsDs.ProjectsDataTable(); iCampaign.TACS.Data.ProjectsDsTableAdapters.ProjectsTableAdapter tableAdapter = new iCampaign.TACS.Data.ProjectsDsTableAdapters.ProjectsTableAdapter(); tableAdapter.Connection = new SqlConnection(TacsSession.ConnectionString); // Try to get the data from the database server try { tableAdapter.Connection.Open(); tableAdapter.FillByAcct(dataTable, acctId); } catch (Exception ex) { throw ex; } finally { tableAdapter.Connection.Close(); } return dataTable; }
/// <summary> /// Add a new project to an account in the TACS.NET database. /// </summary> /// <param name="project">iCampaign.TACS.ProjectProfile: object.</param> /// <param name="credentials">iCampaign.TACS.Client.Credentials: object.</param> /// <returns>string: Status message.</returns> internal string AddProject(ProjectProfile project, Credentials credentials) { bool errorStatus = false; string result = String.Empty; // Check to see if user has sufficient privilege if (!credentials.AccountOwner) { result = TacsSession.MSG_INSUFPRIV; errorStatus = true; } // If no error exists, create the database objects and insert the record if (!errorStatus) { Data.ProjectsDs.ProjectsDataTable projectTable = new ProjectsDs.ProjectsDataTable(); Data.ProjectsDs.ProjectsRow row = projectTable.NewProjectsRow(); Data.ProjectsDsTableAdapters.ProjectsTableAdapter tableAdapter = new iCampaign.TACS.Data.ProjectsDsTableAdapters.ProjectsTableAdapter(); tableAdapter.Connection = new SqlConnection(TacsSession.ConnectionString); try { tableAdapter.Connection.Open(); row.AcctId = credentials.AccountId; row.AppCode = project.ApplicationCode; row.ConnectorType = project.ConnectorType.ToString(); row.CreatedOn = DateTime.Now; row.Database = project.Database; row.DataSource = project.DataSource; row.Password = project.Password; row.Project = project.Project; row.Username = project.Username; projectTable.AddProjectsRow(row); tableAdapter.Update(projectTable); } catch (Exception ex) { errorStatus = true; result = ex.Message; } finally { tableAdapter.Connection.Close(); } } if (!errorStatus) result = TacsSession.MSG_SUCCESS; return result; }
/// <summary> /// Get project profile from TACS.NET database for specified project. /// </summary> /// <param name="project">string: Project name.</param> /// <param name="role">string: Caller role being used.</param> /// <param name="credentials">iCampaign.TACS.Client.Credentials: object.</param> /// <returns>iCampaign.TACS.ProjectProfile: object.</returns> internal ProjectProfile GetProject(string project, string role, iCampaign.TACS.Client.Credentials credentials) { bool errorStatus = false; ProjectProfile result = new ProjectProfile(); // Check to see if user has sufficient access if (!credentials.HasAccess(role, AccessLevelEnum.Owner)) { errorStatus = true; result.ErrorMessage = TacsSession.MSG_INSUFPRIV; } // Check for valid session token if (!TacsSession.IsTokenValid(credentials.Username, credentials.SessionToken)) { errorStatus = true; result.ErrorMessage = TacsSession.MSG_INVALSESS; } // Check to see if project is valid if (!errorStatus) { if (!TacsSession.IsProjectValid(credentials.ApplicationCode, project)) { errorStatus = true; result.ErrorMessage = TacsSession.MSG_UNKPROJECT; } } // If no error exists, go ahead and get project profile if (!errorStatus) { Data.ProjectsDs.ProjectsDataTable projectTable = new ProjectsDs.ProjectsDataTable(); Data.ProjectsDsTableAdapters.ProjectsTableAdapter tableAdapter = new iCampaign.TACS.Data.ProjectsDsTableAdapters.ProjectsTableAdapter(); Data.ProjectsDs.ProjectsRow row = null; tableAdapter.Connection = new SqlConnection(TacsSession.ConnectionString); try { tableAdapter.Connection.Open(); tableAdapter.FillByProject(projectTable, project); row = projectTable[0]; } catch (Exception ex) { result.ErrorMessage = ex.Message; errorStatus = true; } finally { tableAdapter.Connection.Close(); } if (!errorStatus) { result.Project = row.Project; result.ConnectorType = TacsSession.GetConnectorType(row.ConnectorType); result.DataSource = row.DataSource; result.Database = row.Database; result.Username = row.Username; result.Password = row.Password; result.CreatedOn = row.CreatedOn; result.ApplicationCode = row.AppCode; result.AccountId = row.AcctId; result.ErrorMessage = TacsSession.MSG_SUCCESS; } } return result; }