Exemplo n.º 1
0
        /// <summary>
        /// 添加Demo
        /// </summary>
        /// <param name="Name"></param>
        /// <param name="Sex"></param>
        /// <param name="Age"></param>
        /// <param name="Remark"></param>
        /// <returns></returns>
        public ResultModel <bool> InsertDemo(string Name, string Sex, int Age, string Remark)
        {
            var result = new ResultModel <bool>();

            try
            {
                _demoRepository.BeginTran(); //开始事务
                long             Id        = IdWorkerHelper.NewId();
                string           sql       = "insert into Demo(Id,Name,Sex,Age,Remark) values(@Id,@Name,@Sex,@Age,@Remark)";
                SugarParameter[] Parameter = new SugarParameter[]
                {
                    new SugarParameter("@Id", Id),
                    new SugarParameter("@Name", Name),
                    new SugarParameter("@Sex", Sex),
                    new SugarParameter("@Age", Age),
                    new SugarParameter("@Remark", Remark)
                };
                result.Data = _demoRepository.ExecuteSql(sql, Parameter);
                _demoRepository.CommitTran();//提交事务
                return(result);
            }
            catch (Exception ex)
            {
                _demoRepository.RollbackTran();//回滚事务
                throw ex;
            }
        }