/// <summary> /// 更新一条数据 /// </summary> public void Update(Wuyiju.Model.Attribute model) { StringBuilder sql = new StringBuilder(); sql.Append("update ec_attribute set "); sql.Append(" name = @name , "); sql.Append(" pid = @pid , "); sql.Append(" level = @level , "); sql.Append(" sort = @sort , "); sql.Append(" status = @status , "); sql.Append(" input = @input , "); sql.Append(" type = @type , "); sql.Append(" recommend = @recommend , "); sql.Append(" extend1 = @extend1 , "); sql.Append(" extend2 = @extend2 "); 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("更新数据无效"); } }
/// <summary> /// 增加一条数据 /// </summary> public void Add(Wuyiju.Model.Attribute obj) { if (obj == null) { throw new ApplicationException("参数不能为空"); } using (var db = new DataContext()) { var _dao = this.GetDao(db); _dao.Insert(obj); } }
/// <summary> /// 删除一条数据 /// </summary> public void Remove(Wuyiju.Model.Attribute obj) { if (obj == null) { throw new ApplicationException("参数不能为空"); } using (var db = new DataContext()) { var _dao = this.GetDao(db); var old = _dao.Get(obj.Id); if (old == null) { throw new ApplicationException("非法操作记录不存在"); } _dao.Delete(obj.Id); } }
/// <summary> /// 增加一条数据 /// </summary> public void Insert(Wuyiju.Model.Attribute model) { StringBuilder sql = new StringBuilder(); sql.Append("insert into ec_attribute("); sql.Append("name,pid,level,sort,status,input,type,recommend,extend1,extend2"); sql.Append(") values ("); sql.Append("@name,@pid,@level,@sort,@status,@input,@type,@recommend,@extend1,@extend2"); sql.Append(") "); DynamicParameters param = new DynamicParameters(); if (model != null) { param.AddDynamicParams(model); } var rows = db.Execute(sql, param); if (rows < 1) { throw new ApplicationException("插入数据无效"); } }