コード例 #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);
        }
コード例 #2
0
ファイル: DAL.cs プロジェクト: jancychr/smart-study
    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);
    }
コード例 #3
0
ファイル: DAL.cs プロジェクト: jancychr/smart-study
    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);
    }
コード例 #4
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);
        }