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