Beispiel #1
0
        public static void UpdatePost(POST editedPost)
        {
            if (editedPost.Description == null)
            {
                editedPost.Description = "";
            }

            if (editedPost.Tags == null)
            {
                editedPost.Tags = "";
            }

            if (editedPost.Title == null)
            {
                editedPost.Title = "";
            }

            using (SqliteConnection con = DataModules.DBConnection())
            {
                string        query = "UPDATE POSTS SET Description = @description, Tags = @tags, Title = @title, Deleted = @deleted WHERE Id = @id";
                SqliteCommand c     = new SqliteCommand(query, con);
                c.Parameters.AddWithValue("@description", editedPost.Description);
                c.Parameters.AddWithValue("@tags", editedPost.Tags);
                c.Parameters.AddWithValue("@title", editedPost.Title);
                c.Parameters.AddWithValue("@deleted", editedPost.Deleted);
                c.Parameters.AddWithValue("@id", editedPost.Id);
                con.Open();
                c.ExecuteNonQuery();
                con.Close();
            }
        }
Beispiel #2
0
 public static void AddPost(POST newPost)
 {
     using (IDbConnection con = DataModules.DBConnection())
     {
         con.Open();
         con.Insert <POST>(newPost);
         con.Close();
     }
     return;
 }
Beispiel #3
0
        public static POST GetPost(int id)
        {
            List <POST> result;

            using (IDbConnection con = DataModules.DBConnection())
            {
                string query = "SELECT Title, ImgUrl, Description, Tags, Date FROM POSTS WHERE Id = " + id;
                con.Open();
                result = con.Query <POST>(query).ToList <POST>();
                con.Close();
            }
            return(result.First <POST>());
        }
Beispiel #4
0
        public static List <POST> SearchPosts(string term)
        {
            List <POST> result;

            using (IDbConnection con = DataModules.DBConnection())
            {
                string query = "SELECT Id, Title, ImgUrl, Description, Tags, Date FROM POSTS WHERE Deleted = 0 AND Tags LIKE '%" + term + "%' ORDER BY Date DESC";

                con.Open();
                result = con.Query <POST>(query).ToList <POST>();
                con.Close();
            }
            return(result);
        }