Esempio n. 1
0
        public ExecuteResult AddComment(BlogCommentAddPageDTO dto, IUserBasicInfo userInfo)
        {
            ExecuteResult result = new ExecuteResult()
            {
                IsSuccess = true
            };

            BlogCommentEntity commentEntity = Mapper.DynamicMap <BlogCommentEntity>(dto);

            commentEntity.InsertTime = DateTime.Now;
            commentEntity.UserID     = userInfo.UserID;
            commentEntity.RealName   = userInfo.RealName;

            MyTransaction transaction = this._commentDal.OpenTransaction();

            try
            {
                this._commentDal.Add(commentEntity);

                this._blogDal.UpdateBlogComment(dto.BlogID, 1);

                transaction.Commit();
            }
            catch (Exception ex)
            {
                transaction.Rollback();
                throw ex;
            }

            return(result);
        }
Esempio n. 2
0
        //Adds a new file.
        public void AddFile(File file)
        {
            bool          isConnOpen = false;
            string        sql        = "INSERT INTO userfiles (file_owner, file_title, link) VALUES(@fileOwner, @fileTitle, @link)";
            NpgsqlCommand cmd        = new NpgsqlCommand(sql, MyConnection);

            cmd.Parameters.AddWithValue("@fileOwner", file.FileOwner);
            cmd.Parameters.AddWithValue("@fileTitle", file.FileTitle);
            cmd.Parameters.AddWithValue("@link", file.Link);

            if (MyConnection.State == System.Data.ConnectionState.Closed)
            {
                MyConnection.Open();
                isConnOpen    = true;
                MyTransaction = MyConnection.BeginTransaction();
            }

            if (MyTransaction != null)
            {
                //used to participate in an opened trasaction happening somewhere else
                //assign the Transaction property to the opened transaction
                cmd.Transaction = MyTransaction;
            }

            cmd.ExecuteNonQuery();
            MyTransaction.Commit();

            if (isConnOpen)
            {
                MyConnection.Close();
                isConnOpen = false;
            }
        }
Esempio n. 3
0
    public int ExeTransactSql(string sSQL, SortedList paramList)
    {
        SqlTransaction MyTransaction;

        //String _ConnString = System.Configuration.ConfigurationManager.ConnectionStrings["connString"].ConnectionString;

        SqlConnection myConnection = new SqlConnection(_ConnString);

        myConnection.Open();

        MyTransaction = myConnection.BeginTransaction();

        SqlCommand cmd = new SqlCommand(sSQL, myConnection, MyTransaction);

        int result;

        try
        {
            cmd.CommandType = CommandType.StoredProcedure;
            for (int x = 0; x <= paramList.Count - 1; x++)
            {
                cmd.Parameters.Add((String)paramList.GetKey(x), paramList.GetByIndex(x));
            }

            result = Convert.ToInt32(cmd.ExecuteNonQuery());

            MyTransaction.Commit();

            cmd.Dispose();
            cmd = null;
            myConnection.Close();
        }
        catch (Exception ex)
        {
            if (ex.ToString() == "")
            {
            }
            MyTransaction.Rollback();
            result = -1;
            //ErrorHandler.WriteError(Convert.ToString(ex));
            if (myConnection.State == ConnectionState.Open)
            {
                myConnection.Close();
            }
            myConnection.Dispose();
            cmd.Dispose();
            MyTransaction.Dispose();
        }
        return(result);
    }
Esempio n. 4
0
    public DataTable GetDataTableWithTransact(string sp, SortedList paramList)
    {
        SqlTransaction MyTransaction;
        DataTable      dt           = new DataTable();
        SqlConnection  myConnection = new SqlConnection(_ConnString);

        myConnection.Open();
        MyTransaction = myConnection.BeginTransaction();
        SqlCommand cmd = new SqlCommand(sp, myConnection, MyTransaction);

        try
        {
            cmd.Connection  = myConnection;
            cmd.CommandText = sp;
            cmd.CommandType = CommandType.StoredProcedure;

            for (int x = 0; x <= paramList.Count - 1; x++)
            {
                cmd.Parameters.Add((String)paramList.GetKey(x), paramList.GetByIndex(x));
            }

            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(dt);
            da.Dispose();
            MyTransaction.Commit();

            cmd.Dispose();
            cmd = null;
            myConnection.Close();
        }
        catch (Exception ex)
        {
            if (ex.ToString() == "")
            {
            }
            MyTransaction.Rollback();
            dt = null;
            //ErrorHandler.WriteError(Convert.ToString(ex));
            if (myConnection.State == ConnectionState.Open)
            {
                myConnection.Close();
            }
            myConnection.Dispose();
            cmd.Dispose();
            MyTransaction.Dispose();
        }
        return(dt);
    }
Esempio n. 5
0
        public ExecuteResult AddBlogTraffic(long blogID, string ip)
        {
            ExecuteResult result = new ExecuteResult()
            {
                IsSuccess = true
            };

            if (_trafficDal.ExistView(blogID, ip))
            {
                return(result);
            }

            var blogEntity = base.Single(m => m.ID == blogID);

            if (blogEntity == null)
            {
                return(result);
            }

            BlogTrafficLogEntity trafficEntity = new BlogTrafficLogEntity()
            {
                BlogID     = blogID,
                IP         = ip,
                InsertTime = DateTime.Now
            };

            blogEntity.Traffic += 1;

            MyTransaction transaction = OpenTransaction();

            try
            {
                long id = _trafficDal.Add(trafficEntity, true);

                base.UpdateOnly(blogEntity, m => new { m.Traffic }, m => m.ID == blogID);

                transaction.Commit();
            }
            catch (Exception ex)
            {
                transaction.Rollback();
                throw ex;
            }

            return(result);
        }