Example #1
0
        /// <summary>
        /// Delete NotesPosted using NotesPosted Object
        /// </summary>
        /// <param name="notesPosted"></param>
        public void Delete(NotesPosted notesPosted)
        {
            if (Exists(notesPosted.Username))
            {
                string query = $"DELETE FROM {Table} WHERE Username = @username;";

                List <MySqlParameter> parameters = new List <MySqlParameter>
                {
                    new MySqlParameter("username", MySqlDbType.VarChar)
                    {
                        Value = notesPosted.Username
                    }
                };

                if (functions.ExecuteNonQuery(query, parameters))
                {
                    Debug.WriteLine("DeleteNotesPosted: The notesPosted was deleted successfully.");
                }
                else
                {
                    Debug.WriteLine("DeleteNotesPosted: An error has occured.");
                }
            }
            else
            {
                Debug.WriteLine("DeleteNotesPosted: Cannot delete notesPosted");
            }
        }
Example #2
0
        /// <summary>
        /// Inserts NotesPosted into Sql Database
        /// </summary>
        /// <param name="notesPosted">NotesPosted Object</param>
        public void Insert(NotesPosted notesPosted)
        {
            if (!Exists(notesPosted.Username))
            {
                string query =
                    $"INSERT INTO {Table} (Text, `TimeStamp`, Username, Email, TaskId)" +
                    $" VALUES(@text, @tstamp, @username, @email, @taskid);";

                List <MySqlParameter> parameters = new List <MySqlParameter>
                {
                    new MySqlParameter("text", MySqlDbType.VarChar)
                    {
                        Value = notesPosted.Text
                    },
                    new MySqlParameter("tstamp", MySqlDbType.DateTime)
                    {
                        Value = notesPosted.TimeStamp
                    },
                    new MySqlParameter("username", MySqlDbType.VarChar)
                    {
                        Value = notesPosted.Username
                    },
                    new MySqlParameter("email", MySqlDbType.VarChar)
                    {
                        Value = notesPosted.Email
                    },
                    new MySqlParameter("taskid", MySqlDbType.VarChar)
                    {
                        Value = notesPosted.TaskId
                    },
                };

                if (functions.ExecuteNonQuery(query, parameters))
                {
                    Debug.WriteLine("InsertNotesPosted: The notesPosted was added successfully.");
                }
                else
                {
                    Debug.WriteLine("InsertNotesPosted: An error has occured.");
                }
            }
        }
Example #3
0
        /// <summary>
        /// Get NotesPosted Object From Sql Database
        /// </summary>
        /// <param name="username">Primary Key</param>
        /// <returns>NotesPosted Object</returns>
        public NotesPosted Get(string username)
        {
            if (Exists(username))
            {
                string query =
                    $"SELECT Text, `TimeStamp`, Username, Email, TaskId " +
                    $"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];
                    NotesPosted notesPosted = new NotesPosted
                    {
                        Text      = row["text"].ToString(),
                        TimeStamp = Convert.ToDateTime(row["timestamp"]),
                        Username  = row["username"].ToString(),
                        Email     = row["email"].ToString(),
                        TaskId    = row["taskid"].ToString()
                    };
                    return(notesPosted);
                }
                else
                {
                    Debug.WriteLine("GetNotesPosted: An error has occured while trying to get notesPosted.");
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }