Пример #1
0
    //--------------------------------------------------------------------
    // Build the Insert command String(commentFile)
    //--------------------------------------------------------------------
    private String BuildInsertCommand(CommentFile CommentFile)
    {
        String command;

        StringBuilder sb = new StringBuilder();

        // use a string builder to create the dynamic string
        sb.AppendFormat("Values('{0}', {1})", CommentFile.FilePath1, CommentFile.CommentID.ToString());
        String prefix = "INSERT INTO CommentFiles " + "(FilePath, commentID) ";

        command = prefix + sb.ToString();

        return(command);
    }
Пример #2
0
    //--------------------------------------------------------------------------------------------------
    // This method inserts a commentFile to the commentFiles table
    //--------------------------------------------------------------------------------------------------
    public int insert(CommentFile CommentFile)
    {
        SqlConnection con;
        SqlCommand    cmd;

        try
        {
            con = connect("DBConnectionString"); // create the connection
        }
        catch (Exception ex)
        {
            // write to log
            throw (ex);
        }

        String cStr = BuildInsertCommand(CommentFile); // helper method to build the insert string

        cmd = CreateCommand(cStr, con);                // create the command

        try
        {
            int numEffected = cmd.ExecuteNonQuery(); // execute the command
            return(numEffected);
        }
        catch (Exception ex)
        {
            return(0);

            // write to log
            throw (ex);
        }

        finally
        {
            if (con != null)
            {
                // close the db connection
                con.Close();
            }
        }
    }
Пример #3
0
    //---------------------------------------------------------------------------------
    // Read Comments Files list
    //---------------------------------------------------------------------------------
    public List <CommentFile> getCFilesList()
    {
        List <CommentFile> commentsFilesList = new List <CommentFile>();
        SqlConnection      con = null;

        // classEX enter your code here

        try
        {
            con = connect("DBConnectionString"); // create a connection to the database using the connection String defined in the web config file

            String     selectSTR = "SELECT * FROM CommentFiles";
            SqlCommand cmd       = new SqlCommand(selectSTR, con);

            // get a reader
            SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); // CommandBehavior.CloseConnection: the connection will be closed after reading has reached the end

            while (dr.Read())
            {   // Read till the end of the data into a row
                CommentFile cf = new CommentFile();

                cf.FilePath1 = (string)dr["FilePath"];
                cf.CommentID = Convert.ToInt32(dr["commentID"]);
                commentsFilesList.Add(cf);
            }

            return(commentsFilesList);
        }
        catch (Exception ex)
        {
            // write to log
            throw (ex);
        }
        finally
        {
            if (con != null)
            {
                con.Close();
            }
        }
    }
Пример #4
0
        public void Post([FromBody] CommentFile[] arr)
        {
            CommentFile cf = new CommentFile();

            cf.insert(arr);
        }
Пример #5
0
 public ExtendedComment(CommentFile comment)
 {
     _comment = comment;
 }