Пример #1
0
        /// <summary>
        /// Adds a report to a post
        /// </summary>
        ///  <param name="Post">Post that needs to be Reported</param>
        /// <returns>true if database allows changes false if not</returns>
        public static bool ReportPost(Post Post)
        {
            bool Check = false;
            int  ID    = DatabaseGetHighestID.GetHighestID("Post");

            if (DatabaseConnectie.OpenConnection())
            {
                try
                {
                    DatabaseConnectie.OpenConnection();
                    SqlCommand cmd = new SqlCommand();
                    cmd.Connection = DatabaseConnectie.connect;

                    cmd.CommandText = "UPDATE Post SET Rapportaties = (Rapportaties + 1) WHERE ID = @ID";;
                    cmd.Parameters.Add(new SqlParameter("ID", Post.ID));
                    cmd.ExecuteNonQuery();

                    Check = true;
                }
                catch (SqlException e)
                {
                    Console.WriteLine("Query Failed: " + e.StackTrace + e.Message.ToString());
                    Check = false;
                }
                finally
                {
                    DatabaseConnectie.CloseConnection();
                }
            }

            return(Check);
        }
Пример #2
0
        /// <summary>
        /// Gets all post that have below 5 reports
        /// </summary>
        /// <returns>A list with posts</returns>
        public static List <Post> GetSafePost()
        {
            List <Post> Postlist = new List <Post>();

            byte[] File;
            string Attachment;

            if (DatabaseConnectie.OpenConnection())
            {
                try
                {
                    DatabaseConnectie.OpenConnection();
                    SqlCommand cmd = new SqlCommand();
                    cmd.Connection = DatabaseConnectie.connect;

                    cmd.CommandText = "SELECT * FROM Post WHERE Rapportaties < 5 AND PostID IS NULL";
                    SqlDataReader reader = cmd.ExecuteReader();

                    while (reader.Read())
                    {
                        int      ID         = Convert.ToInt32(reader["ID"]);
                        int      TimelineID = Convert.ToInt32(reader["TijdlijnID"]);
                        int      AccountID  = Convert.ToInt32(reader["AccountID"]);
                        string   PostID     = (reader["PostID"].ToString());
                        string   Category   = (reader["Categorie"].ToString());
                        string   Text       = (reader["Tekstinhoud"].ToString());
                        DateTime Date       = Convert.ToDateTime(reader["Datum"]);
                        int      Likes      = Convert.ToInt32(reader["Likes"]);
                        int      Reports    = Convert.ToInt32(reader["Rapportaties"]);
                        bool     Readable   = (Convert.ToBoolean(reader["Leesbaar"]));
                        if (reader["Bestand"] != DBNull.Value)
                        {
                            Attachment = "Bijlage";
                            File       = (byte[])reader["Bestand"];
                        }
                        else
                        {
                            Attachment = "None";
                            File       = null;
                        }

                        Account Account = DatabaseGetAccounts.GetSingleAccountID(AccountID);

                        Post GottenPost = new Post(ID, Text, Category, AccountID, TimelineID, Likes, Account, File, Attachment, PostID);
                        Postlist.Add(GottenPost);
                    }
                    return(Postlist);
                }
                catch (SqlException e)
                {
                    Console.WriteLine("Query Failed: " + e.StackTrace + e.Message.ToString());
                }
                finally
                {
                    DatabaseConnectie.CloseConnection();
                }
            }
            return(Postlist);
        } //Gets all posts who havent been reported 5 times or more
Пример #3
0
        /// <summary>
        /// //Returns the posts that contain the searched word and category (ook slecht)
        /// </summary>
        /// <param name="Fwoord">Woord van post</param>
        /// <param name="Fcat">categorie van post</param>
        /// <returns>A list with posts</returns>
        public static List <Post> GetWordCategory(string Fwoord, string Fcat)
        {
            List <Post> Postlist = new List <Post>();

            byte[] File;
            string Attachment;

            if (DatabaseConnectie.OpenConnection())
            {
                try
                {
                    DatabaseConnectie.OpenConnection();
                    SqlCommand cmd = new SqlCommand();
                    cmd.Connection = DatabaseConnectie.connect;

                    cmd.CommandText = "SELECT p.Categorie, p.AccountID, p.TijdlijnID, p.Tekstinhoud, p.Likes, a.Naam, p.Bestand FROM Post p, Account a WHERE p.AccountID = a.ID AND p.Tekstinhoud LIKE " + "'%" + Fwoord + "%'" + "AND p.Categorie = " + "'" + Fcat + "'" + ";";
                    SqlDataReader reader = cmd.ExecuteReader();

                    while (reader.Read())
                    {
                        //int ID = Convert.ToInt32(reader["ID"]);
                        int TimelineID = Convert.ToInt32(reader["TijdlijnID"]);
                        int AccountID  = Convert.ToInt32(reader["AccountID"]);
                        //string PostID = (reader["PostID"].ToString());
                        string Category = (reader["Categorie"].ToString());
                        string Text     = (reader["Tekstinhoud"].ToString());
                        //DateTime Date = Convert.ToDateTime(reader["Datum"]);
                        int Likes = Convert.ToInt32(reader["Likes"]);
                        //int Reports = Convert.ToInt32(reader["Rapportaties"]);
                        //bool Readable = (Convert.ToBoolean(reader["Leesbaar"]));
                        if (reader["Bestand"] != DBNull.Value)
                        {
                            Attachment = "Bijlage";
                            File       = (byte[])reader["Bestand"];
                        }
                        else
                        {
                            Attachment = "None";
                            File       = null;
                        }

                        Account Account = DatabaseGetAccounts.GetSingleAccountID(AccountID);

                        Post GottenPost = new Post(Text, Category, AccountID, TimelineID, Likes, Account, File, Attachment);
                        Postlist.Add(GottenPost);
                    }
                    return(Postlist);
                }
                catch (SqlException e)
                {
                    Console.WriteLine("Query Failed: " + e.StackTrace + e.Message.ToString());
                }
                finally
                {
                    DatabaseConnectie.CloseConnection();
                }
            }
            return(Postlist);
        }
Пример #4
0
        } //Adding the gottenpost from the business layer to the database

        /// <summary>
        /// Adds a reaction to posts
        /// </summary>
        ///  <param name="Post">Post that needs to be added (reaction)</param>
        /// <returns>true if database allows changes false if not</returns>
        public static bool AddReaction(Post Post)
        {
            bool Check = false;
            int  ID    = DatabaseGetHighestID.GetHighestID("Post");

            if (DatabaseConnectie.OpenConnection())
            {
                try
                {
                    DatabaseConnectie.OpenConnection();
                    SqlCommand cmd = new SqlCommand();
                    cmd.Connection = DatabaseConnectie.connect;

                    if (Post.File == null)
                    {
                        cmd.CommandText = "INSERT INTO Post (ID, Tekstinhoud, postID, Datum, Categorie, TijdlijnID, AccountID) VALUES (@ID, @Text, @PostID, @Date, @Category, @TimelineID, @AccountID)";
                    }
                    else
                    {
                        cmd.CommandText = "INSERT INTO Post (ID, Tekstinhoud, postID, Datum, Categorie, TijdlijnID, AccountID, Bestand) VALUES (@ID, @Text, @PostID, @Date, @Category, @TimelineID, @AccountID, @File)";
                        cmd.Parameters.Add(new SqlParameter("File", Post.File));
                    }
                    cmd.Parameters.Add(new SqlParameter("ID", ID));
                    cmd.Parameters.Add(new SqlParameter("Text", Post.Text));
                    cmd.Parameters.Add(new SqlParameter("postID", Post.PostID));
                    cmd.Parameters.Add(new SqlParameter("Date", System.DateTime.Now));
                    cmd.Parameters.Add(new SqlParameter("Category", Post.Category));
                    cmd.Parameters.Add(new SqlParameter("TimelineID", Post.TimeLineID));
                    cmd.Parameters.Add(new SqlParameter("AccountID", Post.AccountID));
                    cmd.ExecuteNonQuery();

                    Check = true;
                }
                catch (SqlException e)
                {
                    Console.WriteLine("Query Failed: " + e.StackTrace + e.Message.ToString());
                    Check = false;
                }
                finally
                {
                    DatabaseConnectie.CloseConnection();
                }
            }

            return(Check);
        }
Пример #5
0
        public void DatabaseConnectionTest()
        {
            bool Check = DatabaseConnectie.OpenConnection();

            Assert.AreEqual(true, Check);
        }