/// <summary>
        /// 带事务的Update
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="trans">The trans.</param>
        /// <returns></returns>
        /// <remarks>2016/6/10 17:42:50</remarks>
        public bool Update(EuropeGamblerecordEntity entity, DbTransaction trans = null)
        {
            var       database       = new SqlDatabase(this.ConnectionString);
            DbCommand commandWrapper = database.GetStoredProcCommand("dbo.P_EuropeGamblerecord_Update");

            database.AddInParameter(commandWrapper, "@Idx", DbType.Int32, entity.Idx);
            database.AddInParameter(commandWrapper, "@ManagerId", DbType.Guid, entity.ManagerId);
            database.AddInParameter(commandWrapper, "@MatchId", DbType.Int32, entity.MatchId);
            database.AddInParameter(commandWrapper, "@GambleType", DbType.Int32, entity.GambleType);
            database.AddInParameter(commandWrapper, "@Point", DbType.Int32, entity.Point);
            database.AddInParameter(commandWrapper, "@ReturnPoint", DbType.Int32, entity.ReturnPoint);
            database.AddInParameter(commandWrapper, "@IsSendPrize", DbType.Boolean, entity.IsSendPrize);
            database.AddInParameter(commandWrapper, "@IsGambleCorrect", DbType.Boolean, entity.IsGambleCorrect);
            database.AddInParameter(commandWrapper, "@UpdateTime", DbType.DateTime, entity.UpdateTime);
            database.AddInParameter(commandWrapper, "@RowTime", DbType.DateTime, entity.RowTime);


            int results = 0;

            if (trans != null)
            {
                results = database.ExecuteNonQuery(commandWrapper, trans);
            }
            else
            {
                results = database.ExecuteNonQuery(commandWrapper);
            }

            entity.Idx = (System.Int32)database.GetParameterValue(commandWrapper, "@Idx");

            return(Convert.ToBoolean(results));
        }
        /// <summary>
        /// 将IDataReader的当前记录读取到EuropeGamblerecordEntity 对象
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        public EuropeGamblerecordEntity LoadSingleRow(IDataReader reader)
        {
            var obj = new EuropeGamblerecordEntity();

            obj.Idx             = (System.Int32)reader["Idx"];
            obj.ManagerId       = (System.Guid)reader["ManagerId"];
            obj.MatchId         = (System.Int32)reader["MatchId"];
            obj.GambleType      = (System.Int32)reader["GambleType"];
            obj.Point           = (System.Int32)reader["Point"];
            obj.ReturnPoint     = (System.Int32)reader["ReturnPoint"];
            obj.IsSendPrize     = (System.Boolean)reader["IsSendPrize"];
            obj.IsGambleCorrect = (System.Boolean)reader["IsGambleCorrect"];
            obj.UpdateTime      = (System.DateTime)reader["UpdateTime"];
            obj.RowTime         = (System.DateTime)reader["RowTime"];

            return(obj);
        }
        /// <summary>
        /// GetById
        /// </summary>
        /// <param name="idx">idx</param>
        /// <returns>EuropeGamblerecordEntity</returns>
        /// <remarks>2016/6/10 17:42:50</remarks>
        public EuropeGamblerecordEntity GetById(System.Int32 idx)
        {
            var database = new SqlDatabase(this.ConnectionString);

            DbCommand commandWrapper = database.GetStoredProcCommand("P_EuropeGamblerecord_GetById");

            database.AddInParameter(commandWrapper, "@Idx", DbType.Int32, idx);


            EuropeGamblerecordEntity obj = null;

            using (IDataReader reader = database.ExecuteReader(commandWrapper))
            {
                if (reader.Read())
                {
                    obj = LoadSingleRow(reader);
                }
            }
            return(obj);
        }
        /// <summary>
        /// GambleRecord
        /// </summary>
        /// <param name="managerId">managerId</param>
        /// <param name="matchId">matchId</param>
        /// <returns>EuropeGamblerecordEntity</returns>
        /// <remarks>2016/6/10 17:42:50</remarks>
        public EuropeGamblerecordEntity GambleRecord(System.Guid managerId, System.Int32 matchId)
        {
            var database = new SqlDatabase(this.ConnectionString);

            DbCommand commandWrapper = database.GetStoredProcCommand("C_Europe_GambleRecord_GetGamble");

            database.AddInParameter(commandWrapper, "@ManagerId", DbType.Guid, managerId);
            database.AddInParameter(commandWrapper, "@MatchId", DbType.Int32, matchId);


            EuropeGamblerecordEntity obj = null;

            using (IDataReader reader = database.ExecuteReader(commandWrapper))
            {
                if (reader.Read())
                {
                    obj = LoadSingleRow(reader);
                }
            }
            return(obj);
        }
        public static bool Update(EuropeGamblerecordEntity europeGamblerecordEntity, DbTransaction trans = null, string zoneId = "")
        {
            var provider = new EuropeGamblerecordProvider(zoneId);

            return(provider.Update(europeGamblerecordEntity, trans));
        }
Esempio n. 6
0
        /// <summary>
        /// 竞猜比赛
        /// </summary>
        /// <param name="managerId"></param>
        /// <param name="matchId"></param>
        /// <param name="gambleType"></param>
        /// <param name="pointType"></param>
        /// <returns></returns>
        public EuropeGambleMatchResponse GambleMatch(Guid managerId, int matchId, int gambleType, int pointType)
        {
            EuropeGambleMatchResponse response = new EuropeGambleMatchResponse();

            try
            {
                DateTime date    = DateTime.Now;
                var      manager = ManagerCore.Instance.GetManager(managerId);
                if (manager == null)
                {
                    response.Code = (int)MessageCode.MissManager;
                    return(response);
                }
                var match = EuropeConfig.Instance.GetOneMatch(matchId);
                if (match == null)
                {
                    response.Code = (int)MessageCode.NotHaveMatch;
                    return(response);
                }
                if (match.States != (int)EnumEuropeStatus.Gamble || match.MatchTime < date)//不可以竞猜
                {
                    response.Code = (int)MessageCode.HaveGambleTime;
                    return(response);
                }
                var gambleRecord = EuropeGamblerecordMgr.GambleRecord(managerId, matchId);
                if (gambleRecord != null)//已经竞猜过
                {
                    response.Code = (int)MessageCode.HaveGamble;
                    return(response);
                }
                var pointConfig = EuropeConfig.Instance.GetGamblePoint(pointType);
                if (pointConfig == null || pointConfig.VipLevel > manager.VipLevel)//竞猜点卷有误
                {
                    response.Code = (int)MessageCode.PointConfigNotHave;
                    return(response);
                }
                var managerPoint = PayCore.Instance.GetPoint(managerId);
                if (managerPoint < pointConfig.Point)//钻石不足
                {
                    response.Code = (int)MessageCode.NbPointShortage;
                    return(response);
                }
                gambleRecord = new EuropeGamblerecordEntity(0, managerId, matchId, gambleType, pointConfig.Point, 0, false, false, date, date);

                using (var transactionManager = new TransactionManager(Dal.ConnectionFactory.Instance.GetDefault()))
                {
                    transactionManager.BeginTransaction();
                    MessageCode code = MessageCode.FailUpdate;
                    do
                    {
                        if (!EuropeGamblerecordMgr.Insert(gambleRecord, transactionManager.TransactionObject))
                        {
                            break;
                        }
                        code = PayCore.Instance.GambleTrueMatch(managerId, pointConfig.Point, ShareUtil.GenerateComb().ToString(), transactionManager.TransactionObject);
                    } while (false);

                    if (code != MessageCode.Success)
                    {
                        transactionManager.Rollback();
                        response.Code = (int)code;
                        return(response);
                    }
                    transactionManager.Commit();
                    response.Data       = new EuropeGambleMatch();
                    response.Data.Point = managerPoint - pointConfig.Point;
                }
            }
            catch (Exception ex)
            {
                SystemlogMgr.Error("欧洲杯竞猜", ex);
                response.Code = (int)MessageCode.NbParameterError;
            }
            return(response);
        }