/// <summary> /// Delete TaskAbilities using TaskAbilities Object /// </summary> /// <param name="taskAbilities"></param> public void Delete(TaskAbilities taskAbilities) { if (Exists(taskAbilities.Username)) { string query = $"DELETE FROM {Table} WHERE Username = @username;"; List <MySqlParameter> parameters = new List <MySqlParameter> { new MySqlParameter("username", MySqlDbType.VarChar) { Value = taskAbilities.Username } }; if (functions.ExecuteNonQuery(query, parameters)) { Debug.WriteLine("DeleteTaskAbilities: The taskAbilities was deleted successfully."); } else { Debug.WriteLine("DeleteTaskAbilities: An error has occured."); } } else { Debug.WriteLine("DeleteTaskAbilities: Cannot delete taskAbilities"); } }
/// <summary> /// Get TaskAbilities Object From Sql Database /// </summary> /// <param name="username">Primary Key</param> /// <returns>TaskAbilities Object</returns> public TaskAbilities Get(string username) { if (Exists(username)) { string query = $"SELECT Username, Email, TaskId, AssignmentEditing " + $"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]; TaskAbilities taskAbilities = new TaskAbilities { Username = row["username"].ToString(), Email = row["email"].ToString(), TaskId = row["taskid"].ToString(), AssignmentEditing = (int)row["assignmentediting"], }; return(taskAbilities); } else { Debug.WriteLine("GetTaskAbilities: An error has occured while trying to get taskAbilities."); return(null); } } else { return(null); } }
/// <summary> /// Inserts TaskAbilities into Sql Database /// </summary> /// <param name="taskAbilities">TaskAbilities Object</param> public void Insert(TaskAbilities taskAbilities) { if (!Exists(taskAbilities.Username)) { string query = $"INSERT INTO {Table} (Username, Email, TaskId, AssignmentEditing)" + $" VALUES(@username, @email, @taskid, @assignmentid);"; List <MySqlParameter> parameters = new List <MySqlParameter> { new MySqlParameter("username", MySqlDbType.VarChar) { Value = taskAbilities.Username }, new MySqlParameter("email", MySqlDbType.VarChar) { Value = taskAbilities.Email }, new MySqlParameter("taskid", MySqlDbType.VarChar) { Value = taskAbilities.TaskId }, new MySqlParameter("assignmentid", MySqlDbType.VarChar) { Value = taskAbilities.AssignmentEditing }, }; if (functions.ExecuteNonQuery(query, parameters)) { Debug.WriteLine("InsertTaskAbilities: The taskAbilities was added successfully."); } else { Debug.WriteLine("InsertTaskAbilities: An error has occured."); } } }