public Dictionary <string, object> Post([FromForm] string title, [FromForm] string content, [FromForm] string sessionid, [FromForm] int topicid, [FromForm] long attachid)
        {
            Dictionary <string, object> response = new Dictionary <string, object>();

            if (!Program.users.TryGetValue(sessionid, out User user))
            {
                response.Add("status", 1);
                response.Add("msg", "Invalid session");
                return(response);
            }
            if (!user.canpost || user.banned)
            {
                response.Add("status", 4);
                response.Add("msg", "You are not allowed to create threads");
                return(response);
            }
            if (TopicController.IsLocked(topicid))
            {
                response.Add("status", 5);
                response.Add("msg", "This topic is locked from further modifications");
                return(response);
            }
            SqlConnection con = new SqlConnection(Program.Configuration["connectionStrings:splashConString"]);

            con.Open();
            SqlCommand command = new SqlCommand("INSERT INTO threads (title, content, creator_id, topicid, attachid) OUTPUT INSERTED.threadid, INSERTED.ctime, INSERTED.mtime VALUES (@title, @content, @creator_id, @topicid, @attachid);", con);

            command.Parameters.AddWithValue("title", title);
            command.Parameters.AddWithValue("content", content);
            command.Parameters.AddWithValue("creator_id", user.uid);
            command.Parameters.AddWithValue("topicid", topicid);
            if (attachid == 0)
            {
                command.Parameters.AddWithValue("attachid", DBNull.Value);
            }
            else
            {
                command.Parameters.AddWithValue("attachid", attachid);
            }
            SqlDataReader reader = command.ExecuteReader();

            if (reader.HasRows)
            {
                reader.Read();
                response.Add("status", 0);
                response.Add("threadid", reader.GetInt64(0));
                response.Add("ctime", Program.ToUnixTimestamp(reader.GetDateTime(1)));
                response.Add("mtime", Program.ToUnixTimestamp(reader.GetDateTime(2)));
            }
            reader.Dispose();
            con.Close();
            return(response);
        }
Example #2
0
        internal static bool IsLocked(long threadid)
        {
            bool          result = true;
            SqlConnection con    = new SqlConnection(Program.Configuration["connectionStrings:splashConString"]);

            con.Open();
            SqlCommand    command = new SqlCommand("SELECT threads.locked, threads.topicid FROM threads WHERE threadid = " + threadid, con);
            SqlDataReader reader  = command.ExecuteReader();

            if (reader.Read())
            {
                result = reader.GetBoolean(0);
            }
            if (!result)
            {
                result = TopicController.IsLocked(reader.GetInt32(1));
            }
            reader.Dispose();
            con.Close();
            return(result);
        }