Example #1
0
        /// <summary>更新一条数据
        ///
        /// </summary>
        public bool Update(Niunan.Blog.Model.Log model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update `log` set ");
            strSql.Append("createdate=@createdate, type=@type, userid=@userid, username=@username, remark=@remark, ip=@ip, ipaddress=@ipaddress  ");
            strSql.Append(" where id=@id ");
            using (var connection = ConnectionFactory.GetOpenConnection(ConnStr))
            {
                int i = connection.Execute(strSql.ToString(), model);
                return(i > 0);
            }
        }
Example #2
0
        /// <summary>得到一个对象实体
        ///
        /// </summary>
        public Niunan.Blog.Model.Log GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select * from `log` ");
            strSql.Append(" where id=@id ");
            Niunan.Blog.Model.Log model = null;
            using (var connection = ConnectionFactory.GetOpenConnection(ConnStr))
            {
                model = connection.QuerySingleOrDefault <Niunan.Blog.Model.Log>(strSql.ToString(), new { id = id });
            }
            return(model);
        }
Example #3
0
        /// <summary>增加一条数据
        ///
        /// </summary>
        public int Add(Niunan.Blog.Model.Log model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into `log`(");
            strSql.Append("createdate, type, userid, username, remark, ip, ipaddress  )");
            strSql.Append(" values (");
            strSql.Append("@createdate, @type, @userid, @username, @remark, @ip, @ipaddress  )");
            strSql.Append(";select @@IDENTITY");

            using (var connection = ConnectionFactory.GetOpenConnection(ConnStr))
            {
                int i = connection.QuerySingle <int>(strSql.ToString(), model);
                return(i);
            }
        }
Example #4
0
        /// <summary>根据条件得到一个对象实体
        ///
        /// </summary>
        public Niunan.Blog.Model.Log GetModelByCond(string cond)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select * from `log` ");
            if (!string.IsNullOrEmpty(cond))
            {
                strSql.Append(" where " + cond);
            }
            strSql.Append(" limit 1;");
            Niunan.Blog.Model.Log model = null;
            using (var connection = ConnectionFactory.GetOpenConnection(ConnStr))
            {
                model = connection.QuerySingleOrDefault <Niunan.Blog.Model.Log>(strSql.ToString());
            }
            return(model);
        }