Beispiel #1
0
        /// <summary>
        /// 增加金牌
        /// </summary>
        /// <param name="managerId"></param>
        /// <param name="theGoldMedalId"></param>
        /// <param name="count"></param>
        public bool AddTheGoldMedal(Guid managerId, int theGoldMedalId, int count)
        {
            var info = GetInfo(managerId);

            if (!info.AddTheGoldMedal(theGoldMedalId, count))
            {
                return(false);
            }
            OlympicManagerMgr.Update(info);
            return(true);
        }
Beispiel #2
0
        /// <summary>
        /// 兑换奖励
        /// </summary>
        /// <param name="managerId"></param>
        /// <param name="exChangerizeType"></param>
        /// <returns></returns>
        public OlympicExchangeResponse Exchange(Guid managerId, int exChangerizeType)
        {
            OlympicExchangeResponse response = new OlympicExchangeResponse();

            response.Data = new OlympicExchange();
            try
            {
                var info       = GetInfo(managerId);
                var configList = GetExChangerize(exChangerizeType);
                if (configList.Count == 0)
                {
                    return(ResponseHelper.Create <OlympicExchangeResponse>((int)MessageCode.NbParameterError));
                }
                foreach (var item in configList)
                {
                    if (!info.DeductTheGoldMedal(item.TheGoldMedalId, item.TheGoldMedalCount))
                    {
                        return(ResponseHelper.Create <OlympicExchangeResponse>((int)MessageCode.OlympicTheGoldMedalCountNot));
                    }
                }
                var package = ItemCore.Instance.GetPackage(managerId, EnumTransactionType.OlympocExChangerize);
                if (package == null || package.BlankCount <= 0)
                {
                    return(ResponseHelper.Create <OlympicExchangeResponse>((int)MessageCode.ItemPackageFull));
                }
                var messageCode = package.AddItem(configList[0].PrizeItemCode);
                if (messageCode != MessageCode.Success)
                {
                    return(ResponseHelper.Create <OlympicExchangeResponse>((int)messageCode));
                }
                OlympicRecordEntity record = new OlympicRecordEntity(0, managerId, exChangerizeType, configList[0].PrizeItemCode, DateTime.Now);
                using (var transactionManager = new TransactionManager(Dal.ConnectionFactory.Instance.GetConnectionString(EnumDbType.Main)))
                {
                    transactionManager.BeginTransaction();
                    messageCode = MessageCode.NbUpdateFail;
                    do
                    {
                        if (!package.Save(transactionManager.TransactionObject))
                        {
                            break;
                        }
                        if (!OlympicManagerMgr.Update(info, transactionManager.TransactionObject))
                        {
                            break;
                        }
                        if (!OlympicRecordMgr.Insert(record, transactionManager.TransactionObject))
                        {
                            break;
                        }
                        messageCode = MessageCode.Success;
                    } while (false);
                    if (messageCode == MessageCode.Success)
                    {
                        transactionManager.Commit();
                        package.Shadow.Save();
                        response.Data.ItemCode        = configList[0].PrizeItemCode;
                        response.Data.TheGoldMedalDic = info.TheGoldMedalDic;
                    }
                    else
                    {
                        transactionManager.Rollback();
                    }
                }
            }
            catch (Exception ex)
            {
                SystemlogMgr.Error("奥运会兑换奖励", ex);
                response.Code = (int)MessageCode.NbParameterError;
            }
            return(response);
        }