Пример #1
0
        public string Bet(GuessRecordModel guess)
        {
            string               result       = "";
            MessageModel         message      = new MessageModel();
            JavaScriptSerializer jss          = new JavaScriptSerializer();
            HashSet <object>     returnResult = new HashSet <object>();

            //获取竞猜列表
            using (HiGame_V1Entities context = new HiGame_V1Entities())
            {
                //判断氦气是否充足
                bool isEnoughMoney = Asset.IsEnoughMoney(guess.UserID, guess.Money);
                //氦气不足
                if (isEnoughMoney == false)
                {
                    message.Message     = MESSAGE.NOMONEY;
                    message.MessageCode = MESSAGE.NOMONEY_CODE;
                }
                else
                {
                    //向db_GuessRecord表插入数据
                    db_GuessRecord guessInsert = new db_GuessRecord();
                    guessInsert.BetMoney  = guess.Money;
                    guessInsert.GuessID   = guess.GuessID;
                    guessInsert.GuessTime = DateTime.Now;
                    guessInsert.GuessType = 0;
                    guessInsert.Odds      = guess.Odds;
                    guessInsert.OptionID  = guess.TeamID;
                    guessInsert.UserID    = guess.UserID;
                    context.db_GuessRecord.Add(guessInsert);
                    //向Asset表插入数据
                    db_AssetRecord assetRecord = new db_AssetRecord();

                    assetRecord.UserID       = guess.UserID;
                    assetRecord.VirtualMoney = -guess.Money;
                    assetRecord.TrueMoney    = 0;
                    assetRecord.GainWay      = ASSET.GAINWAY_QUIZ;
                    assetRecord.GainTime     = DateTime.Now;
                    assetRecord.State        = ASSET.MONEYSTATE_YES;
                    //时间+操作+收入支出金额
                    assetRecord.Remark = assetRecord.GainTime + " " +
                                         assetRecord.GainWay + " "
                                         + ASSET.PAY_OUT +
                                         assetRecord.VirtualMoney.ToString();

                    //将充值记录加入资产记录表
                    context.db_AssetRecord.Add(assetRecord);

                    context.SaveChanges();

                    message.Message     = MESSAGE.OK;
                    message.MessageCode = MESSAGE.OK_CODE;
                }
                returnResult.Add(message);
            }
            result = jss.Serialize(returnResult);
            return(result);
        }
Пример #2
0
        public HttpResponseMessage Bet([FromBody] GuessRecordModel guess)
        {
            GuessLogic guessLogic = new GuessLogic();

            jsonResult = guessLogic.Bet(guess);

            returnResult.Content = new StringContent(jsonResult, Encoding.UTF8, "application/json");
            return(returnResult);
        }