Exemple #1
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(Wuyiju.Model.Question obj)
        {
            if (obj == null)
            {
                throw new ApplicationException("参数不能为空");
            }

            if (obj.Title.IsNullOrWhiteSpace())
            {
                throw new ApplicationException("标题不能为空");
            }

            if (obj.Info.IsNullOrWhiteSpace())
            {
                throw new ApplicationException("内容不能为空");
            }

            if (obj.Type_Id == 0)
            {
                throw new ApplicationException("分类不能为空");
            }

            using (var db = new DataContext())
            {
                var _dao = this.GetDao(db);
                _dao.Insert(obj);
            }
        }
Exemple #2
0
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public void Remove(Wuyiju.Model.Question obj)
        {
            if (obj == null)
            {
                throw new ApplicationException("参数不能为空");
            }

            var old = dao.Get(obj.Id);

            if (old == null)
            {
                throw new ApplicationException("非法操作记录不存在");
            }
            using (var db = new DataContext())
            {
                var _dao = this.GetDao(db);
                _dao.Delete(obj.Id);
            }
        }
Exemple #3
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(Wuyiju.Model.Question model)
        {
            StringBuilder sql = new StringBuilder();

            sql.Append("update ec_question set ");

            sql.Append(" type_id = @type_id , ");
            sql.Append(" title = @title , ");
            sql.Append(" `from` = @from , ");
            sql.Append(" img = @img , ");
            sql.Append(" url = @url , ");
            sql.Append(" resp = @resp , ");
            sql.Append(" info = @info , ");
            sql.Append(" add_time = @add_time , ");
            sql.Append(" sort_order = @sort_order , ");
            sql.Append(" resp_time = @resp_time , ");
            sql.Append(" is_best = @is_best , ");
            sql.Append(" status = @status , ");
            sql.Append(" seo_title = @seo_title , ");
            sql.Append(" seo_keys = @seo_keys , ");
            sql.Append(" seo_desc = @seo_desc , ");
            sql.Append(" filename = @filename , ");
            sql.Append(" click = @click , ");
            sql.Append(" user_id = @user_id  ");
            sql.Append(" where id=@id ");

            DynamicParameters param = new DynamicParameters();

            if (model != null)
            {
                param.AddDynamicParams(model);
            }

            var rows = db.Execute(sql, param);

            if (rows < 1)
            {
                throw new ApplicationException("更新数据无效");
            }
        }
Exemple #4
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Insert(Wuyiju.Model.Question model)
        {
            StringBuilder sql = new StringBuilder();

            sql.Append("insert into ec_question(");
            sql.Append("type_id,title,`from`,img,url,resp,info,add_time,sort_order,resp_time,is_best,status,seo_title,seo_keys,seo_desc,filename,click,user_id");
            sql.Append(") values (");
            sql.Append("@type_id,@title,@from,@img,@url,@resp,@info,@add_time,@sort_order,@resp_time,@is_best,@status,@seo_title,@seo_keys,@seo_desc,@filename,@click,@user_id");
            sql.Append(") ");

            DynamicParameters param = new DynamicParameters();

            if (model != null)
            {
                param.AddDynamicParams(model);
            }

            var rows = db.Execute(sql, param);

            if (rows < 1)
            {
                throw new ApplicationException("插入数据无效");
            }
        }