/// <summary> /// Delete ProjectAbilities using ProjectAbilities Object /// </summary> /// <param name="projectAbilities"></param> public void Delete(ProjectAbilities projectAbilities) { if (Exists(projectAbilities.Username)) { string query = $"DELETE FROM {Table} WHERE Username = @username;"; List <MySqlParameter> parameters = new List <MySqlParameter> { new MySqlParameter("username", MySqlDbType.VarChar) { Value = projectAbilities.Username } }; if (functions.ExecuteNonQuery(query, parameters)) { Debug.WriteLine("DeleteProjectAbilities: The projectAbilities was deleted successfully."); } else { Debug.WriteLine("DeleteProjectAbilities: An error has occured."); } } else { Debug.WriteLine("DeleteProjectAbilities: Cannot delete projectAbilities"); } }
/// <summary> /// Inserts ProjectAbilities into Sql Database /// </summary> /// <param name="projectAbilities">ProjectAbilities Object</param> public void Insert(ProjectAbilities projectAbilities) { if (!Exists(projectAbilities.Username)) { string query = $"INSERT INTO {Table} (Username, Email, ProjectId, AssignmentEditing, ProjectEditing, CreateProject)" + $" VALUES(@username, @email, @projectId, @assignmentediting, @projectediting, @createproject);"; List <MySqlParameter> parameters = new List <MySqlParameter> { new MySqlParameter("username", MySqlDbType.VarChar) { Value = projectAbilities.Username }, new MySqlParameter("email", MySqlDbType.VarChar) { Value = projectAbilities.Email }, new MySqlParameter("projectId", MySqlDbType.VarChar) { Value = projectAbilities.ProjectId }, new MySqlParameter("assignmentediting", MySqlDbType.Int16) { Value = projectAbilities.AssignmentEditing }, new MySqlParameter("projectediting", MySqlDbType.Int16) { Value = projectAbilities.ProjectEditing }, new MySqlParameter("createproject", MySqlDbType.Int16) { Value = projectAbilities.CreateProject }, }; if (functions.ExecuteNonQuery(query, parameters)) { Debug.WriteLine("InsertProjectAbilities: The projectAbilities was added successfully."); } else { Debug.WriteLine("InsertProjectAbilities: An error has occured."); } } }
/// <summary> /// Get ProjectAbilities Object From Sql Database /// </summary> /// <param name="username">Primary Key</param> /// <returns>ProjectAbilities Object</returns> public ProjectAbilities Get(string username) { if (Exists(username)) { string query = $"SELECT Username, Email, ProjectId, AssignmentEditing, ProjectEditing, CreateProject " + $"FROM {Table} WHERE(Username = @username)"; List <MySqlParameter> parameters = new List <MySqlParameter> { new MySqlParameter("username", MySqlDbType.VarChar) { Value = username } }; if (functions.ExecuteReader(query, parameters, out DataTable dataTable)) { DataRow row = dataTable.Rows[0]; ProjectAbilities projectAbilities = new ProjectAbilities { Username = row["username"].ToString(), Email = row["email"].ToString(), ProjectId = row["projectid"].ToString(), AssignmentEditing = (int)row["assignmentediting"], ProjectEditing = (int)row["projectediting"], CreateProject = (int)row["createproject"], }; return(projectAbilities); } else { Debug.WriteLine("GetProjectAbilities: An error has occured while trying to get projectAbilities."); return(null); } } else { return(null); } }