コード例 #1
0
        public bool createTopic(Topic topic)
        {
            string Author = verifyToken(topic.token);

            if (Author == "")
            {
                ForumException forumException = new ForumException();
                forumException.ErrorCode = 1;
                forumException.Message   = "Invalid token.";
                throw new FaultException <ForumException>(forumException, new FaultReason("Invalid token."));
            }
            bool       result = false;
            string     query  = "INSERT INTO [Topic] (Name, Author, Discussion) VALUES (@Name, @Author, @Discussion)";
            SqlCommand cmd    = new SqlCommand(query, con);

            cmd.Parameters.AddWithValue("@Name", topic.Name);
            cmd.Parameters.AddWithValue("@Author", Author);
            Console.WriteLine(Author);
            cmd.Parameters.AddWithValue("@Discussion", topic.Discussion);
            try
            {
                con.Open();
                int i = cmd.ExecuteNonQuery();
                result = true;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                throw new FaultException <Exception>(ex, new FaultReason(ex.Message));
            }
            finally
            {
                con.Close();
            }
            return(result);
        }
コード例 #2
0
        public bool addComment(Comment comment)
        {
            string Author = verifyToken(comment.token);

            if (Author == "")
            {
                ForumException forumException = new ForumException();
                forumException.ErrorCode = 1;
                forumException.Message   = "Invalid token.";
                throw new FaultException <ForumException>(forumException, new FaultReason("Invalid token."));
            }
            bool       result = false;
            string     query  = "INSERT INTO [Comment] (TopicId, Author, Comment, Timestamp) VALUES (@TopicId, @Author, @Comment, @Timestamp)";
            SqlCommand cmd    = new SqlCommand(query, con);

            cmd.Parameters.AddWithValue("@TopicId", comment.TopicId);
            cmd.Parameters.AddWithValue("@Author", Author);
            cmd.Parameters.AddWithValue("@Comment", comment.Comments);
            cmd.Parameters.AddWithValue("@Timestamp", DateTime.Now);
            try
            {
                con.Open();
                int i = cmd.ExecuteNonQuery();
                result = true;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                throw new FaultException <Exception>(ex, new FaultReason(ex.Message));
            }
            finally
            {
                con.Close();
            }
            return(result);
        }