/// <summary> /// 增加一条数据 /// </summary> public bool Add(WebApi_Model.T_Forum_Gift model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into T_Forum_Gift("); strSql.Append("ForumID,GiftID,Qty,PostUID,ReceiptUID,PostTime)"); strSql.Append(" values ("); strSql.Append("@ForumID,@GiftID,@Qty,@PostUID,@ReceiptUID,@PostTime)"); SqlParameter[] parameters = { new SqlParameter("@ForumID", SqlDbType.Int, 4), new SqlParameter("@GiftID", SqlDbType.Int, 4), new SqlParameter("@Qty", SqlDbType.Int, 4), new SqlParameter("@PostUID", SqlDbType.Int, 4), new SqlParameter("@ReceiptUID", SqlDbType.Int, 4), new SqlParameter("@PostTime", SqlDbType.DateTime) }; parameters[0].Value = model.ForumID; parameters[1].Value = model.GiftID; parameters[2].Value = model.Qty; parameters[3].Value = model.PostUID; parameters[4].Value = model.ReceiptUID; parameters[5].Value = model.PostTime; int rows = DBHelper.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public WebApi_Model.T_Forum_Gift GetModel(int ForumID, int GiftID, int Qty, int PostUID, int ReceiptUID, DateTime PostTime) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 ForumID,GiftID,Qty,PostUID,ReceiptUID,PostTime from T_Forum_Gift "); strSql.Append(" where ForumID=@ForumID and GiftID=@GiftID and Qty=@Qty and PostUID=@PostUID and ReceiptUID=@ReceiptUID and PostTime=@PostTime "); SqlParameter[] parameters = { new SqlParameter("@ForumID", SqlDbType.Int, 4), new SqlParameter("@GiftID", SqlDbType.Int, 4), new SqlParameter("@Qty", SqlDbType.Int, 4), new SqlParameter("@PostUID", SqlDbType.Int, 4), new SqlParameter("@ReceiptUID", SqlDbType.Int, 4), new SqlParameter("@PostTime", SqlDbType.DateTime) }; parameters[0].Value = ForumID; parameters[1].Value = GiftID; parameters[2].Value = Qty; parameters[3].Value = PostUID; parameters[4].Value = ReceiptUID; parameters[5].Value = PostTime; WebApi_Model.T_Forum_Gift model = new WebApi_Model.T_Forum_Gift(); DataSet ds = DBHelper.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
/// <summary> /// 得到一个对象实体 /// </summary> public WebApi_Model.T_Forum_Gift DataRowToModel(DataRow row) { WebApi_Model.T_Forum_Gift model = new WebApi_Model.T_Forum_Gift(); if (row != null) { if (row["ForumID"] != null && row["ForumID"].ToString() != "") { model.ForumID = int.Parse(row["ForumID"].ToString()); } if (row["GiftID"] != null && row["GiftID"].ToString() != "") { model.GiftID = int.Parse(row["GiftID"].ToString()); } if (row["Qty"] != null && row["Qty"].ToString() != "") { model.Qty = int.Parse(row["Qty"].ToString()); } if (row["PostUID"] != null && row["PostUID"].ToString() != "") { model.PostUID = int.Parse(row["PostUID"].ToString()); } if (row["ReceiptUID"] != null && row["ReceiptUID"].ToString() != "") { model.ReceiptUID = int.Parse(row["ReceiptUID"].ToString()); } if (row["PostTime"] != null && row["PostTime"].ToString() != "") { model.PostTime = DateTime.Parse(row["PostTime"].ToString()); } } return(model); }
public IHttpActionResult SendGift(dynamic model) { WebApi_BLL.T_Forum_Gift bll = new WebApi_BLL.T_Forum_Gift(); WebApi_BLL.T_User userbll = new WebApi_BLL.T_User(); WebApi_BLL.T_Gift giftbll = new WebApi_BLL.T_Gift(); WebApi_Model.T_Forum_Gift forumgift = (WebApi_Model.T_Forum_Gift)Newtonsoft.Json.JsonConvert.DeserializeObject(model, typeof(WebApi_Model.T_Forum_Gift)); WebApi_Model.T_User sendUser = userbll.GetModel((int)forumgift.PostUID); WebApi_Model.T_User receiptUser = userbll.GetModel((int)forumgift.ReceiptUID); WebApi_Model.T_Gift gift = giftbll.GetModel((int)forumgift.GiftID); if (sendUser != null && receiptUser != null && gift != null) { int TotalTM = (int)gift.TuiMao * (int)forumgift.Qty; if (sendUser.TuiMao >= TotalTM) { sendUser.TuiMao = sendUser.TuiMao - TotalTM; receiptUser.TuiMao = receiptUser.TuiMao + TotalTM; userbll.Update(sendUser); userbll.Update(receiptUser); forumgift.PostTime = DateTime.Now; bll.Add(forumgift); #region update giftcount DBHelper.GetSingle("update T_Forum_Comment set giftcount = (select giftcount from V_Forum_Gift where ForumID = " + forumgift.ForumID + " and PostUID = " + forumgift.PostUID + ")"); #endregion return(Ok(ReturnJsonResult.GetJsonResult(1, "OK", "腿毛不足!"))); } else { return(Ok(ReturnJsonResult.GetJsonResult(-1, "Error", "腿毛不足!"))); } } else { return(Ok(ReturnJsonResult.GetJsonResult(-1, "Error", "数据格式错误!"))); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(WebApi_Model.T_Forum_Gift model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update T_Forum_Gift set "); strSql.Append("ForumID=@ForumID,"); strSql.Append("GiftID=@GiftID,"); strSql.Append("Qty=@Qty,"); strSql.Append("PostUID=@PostUID,"); strSql.Append("ReceiptUID=@ReceiptUID,"); strSql.Append("PostTime=@PostTime"); strSql.Append(" where ForumID=@ForumID and GiftID=@GiftID and Qty=@Qty and PostUID=@PostUID and ReceiptUID=@ReceiptUID and PostTime=@PostTime "); SqlParameter[] parameters = { new SqlParameter("@ForumID", SqlDbType.Int, 4), new SqlParameter("@GiftID", SqlDbType.Int, 4), new SqlParameter("@Qty", SqlDbType.Int, 4), new SqlParameter("@PostUID", SqlDbType.Int, 4), new SqlParameter("@ReceiptUID", SqlDbType.Int, 4), new SqlParameter("@PostTime", SqlDbType.DateTime) }; parameters[0].Value = model.ForumID; parameters[1].Value = model.GiftID; parameters[2].Value = model.Qty; parameters[3].Value = model.PostUID; parameters[4].Value = model.ReceiptUID; parameters[5].Value = model.PostTime; int rows = DBHelper.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }