Exemple #1
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(WebApi_Model.T_Gift model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update T_Gift set ");
            strSql.Append("GiftName=@GiftName,");
            strSql.Append("GiftICO=@GiftICO,");
            strSql.Append("TuiMao=@TuiMao,");
            strSql.Append("IsActive=@IsActive");
            strSql.Append(" where GiftID=@GiftID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@GiftName", SqlDbType.NVarChar, 30),
                new SqlParameter("@GiftICO",  SqlDbType.NVarChar, 30),
                new SqlParameter("@TuiMao",   SqlDbType.Int,       4),
                new SqlParameter("@IsActive", SqlDbType.Int,       4),
                new SqlParameter("@GiftID",   SqlDbType.Int, 4)
            };
            parameters[0].Value = model.GiftName;
            parameters[1].Value = model.GiftICO;
            parameters[2].Value = model.TuiMao;
            parameters[3].Value = model.IsActive;
            parameters[4].Value = model.GiftID;

            int rows = DBHelper.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #2
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(WebApi_Model.T_Gift model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into T_Gift(");
            strSql.Append("GiftName,GiftICO,TuiMao,IsActive)");
            strSql.Append(" values (");
            strSql.Append("@GiftName,@GiftICO,@TuiMao,@IsActive)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@GiftName", SqlDbType.NVarChar, 30),
                new SqlParameter("@GiftICO",  SqlDbType.NVarChar, 30),
                new SqlParameter("@TuiMao",   SqlDbType.Int,       4),
                new SqlParameter("@IsActive", SqlDbType.Int, 4)
            };
            parameters[0].Value = model.GiftName;
            parameters[1].Value = model.GiftICO;
            parameters[2].Value = model.TuiMao;
            parameters[3].Value = model.IsActive;

            object obj = DBHelper.GetSingle(strSql.ToString(), parameters);

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Exemple #3
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public WebApi_Model.T_Gift DataRowToModel(DataRow row)
 {
     WebApi_Model.T_Gift model = new WebApi_Model.T_Gift();
     if (row != null)
     {
         if (row["GiftID"] != null && row["GiftID"].ToString() != "")
         {
             model.GiftID = int.Parse(row["GiftID"].ToString());
         }
         if (row["GiftName"] != null)
         {
             model.GiftName = row["GiftName"].ToString();
         }
         if (row["GiftICO"] != null)
         {
             model.GiftICO = row["GiftICO"].ToString();
         }
         if (row["TuiMao"] != null && row["TuiMao"].ToString() != "")
         {
             model.TuiMao = int.Parse(row["TuiMao"].ToString());
         }
         if (row["IsActive"] != null && row["IsActive"].ToString() != "")
         {
             model.IsActive = int.Parse(row["IsActive"].ToString());
         }
     }
     return(model);
 }
Exemple #4
0
        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", "数据格式错误!")));
            }
        }
Exemple #5
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public WebApi_Model.T_Gift GetModel(int GiftID)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 GiftID,GiftName,GiftICO,TuiMao,IsActive from T_Gift ");
            strSql.Append(" where GiftID=@GiftID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@GiftID", SqlDbType.Int, 4)
            };
            parameters[0].Value = GiftID;

            WebApi_Model.T_Gift model = new WebApi_Model.T_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);
            }
        }