public bool UpdateBlogItemById(BlogItem b)
        {
            try
            {
                MySqlConnection cnn    = ReturnMYSQLConnection();
                var             query  = "UPDATE BlogItem SET Title=@Title, Message=@Message, CreatedDate=@CreatedDate, Published=@Published, Thumbnail=@Thumbnail WHERE ID = @Id";
                MySqlCommand    newCmd = CreateMYSQLCommandText(query, cnn);

                newCmd.Parameters.AddWithValue("@Id", b.RetrieveId());
                newCmd.Parameters.AddWithValue("@Title", b.RetrieveTitle());
                newCmd.Parameters.AddWithValue("@Message", b.RetrieveMessage());
                newCmd.Parameters.AddWithValue("@CreatedDate", b.CreatedDate);
                newCmd.Parameters.AddWithValue("@Published", b.Publised);
                newCmd.Parameters.AddWithValue("@Thumbnail", b.Thumbnail);

                newCmd.ExecuteNonQuery();
                cnn.Close();
                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            return(false);
        }
Esempio n. 2
0
        public bool CreateNewBlogItem(BlogItem b)
        {
            try
            {
                MySqlConnection cnn    = ReturnMYSQLConnection();
                string          query  = "INSERT INTO BlogItem (Title, Message, CreatedDate, Published) VALUES (@Title, @Message, @CreatedDate, @Published)";
                MySqlCommand    newCmd = CreateMYSQLCommandText(query, cnn);

                newCmd.Parameters.AddWithValue("@Title", b.RetrieveTitle());
                newCmd.Parameters.AddWithValue("@Message", b.RetrieveMessage());
                newCmd.Parameters.AddWithValue("@CreatedDate", b.CreatedDate);
                newCmd.Parameters.AddWithValue("@Published", b.Publised);
                newCmd.ExecuteNonQuery();
                cnn.Close();
                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            return(false);
        }