/// <summary> /// 添加礼券 /// </summary> /// <param name="model">礼券信息</param> /// <returns></returns> public int AddCoupon(CouponInfoModel model) { const string sql = @"INSERT INTO coupon_card (innerid, title, titlesub, amount, logourl, vtype, vstart, vend, value1, value2, maxcount, count, codetype, createdtime, modifiedtime, isenabled) VALUES (@innerid,@title,@titlesub,@amount,@logourl,@vtype,@vstart,@vend,@value1,@value2,@maxcount,@count,@codetype,@createdtime,@modifiedtime,@isenabled);"; using (var conn = Helper.GetConnection()) { var tran = conn.BeginTransaction(); try { conn.Execute(sql, model, tran); tran.Commit(); return 1; } catch (Exception ex) { tran.Rollback(); return 0; } } }
/// <summary> /// 修改礼券 /// </summary> /// <param name="model">礼券信息</param> /// <returns></returns> public int UpdateCoupon(CouponInfoModel model) { //var sql = "update coupon_card set title=@title,titlesub=@titlesub,amount=@amount,logourl=@logourl, where innerid = @innerid"; var sqlStr = new StringBuilder("update coupon_card set "); sqlStr.Append(Helper.CreateField(model).Trim().TrimEnd(',')); sqlStr.Append(" where innerid = @innerid"); using (var conn = Helper.GetConnection()) { var tran = conn.BeginTransaction(); try { conn.Execute(sqlStr.ToString(), model, tran); tran.Commit(); return 1; } catch (Exception ex) { tran.Rollback(); return 0; } } }