Exemplo n.º 1
0
        public MyBlacksResponse DeleteBlack(Guid managerId, int recordId, int pageIndex, int pageSize)
        {
            var friend = FriendManagerMgr.GetById(recordId);

            if (friend == null || friend.ManagerId != managerId || friend.Status != 1)
            {
                return(ResponseHelper.InvalidParameter <MyBlacksResponse>());
            }
            var byFriend = FriendManagerMgr.GetOne(friend.FriendId, managerId);

            if (byFriend != null && byFriend.Status == 1)
            {
                friend.Status = 2;
                FriendManagerMgr.Update(friend);
            }
            else
            {
                FriendManagerMgr.Delete(friend.Idx, friend.RowVersion);
                if (byFriend != null && byFriend.Status == 2)
                {
                    FriendManagerMgr.Delete(byFriend.Idx, byFriend.RowVersion);
                }
            }
            return(GetMyBlacks(managerId, pageIndex, pageSize));
        }
Exemplo n.º 2
0
        public MessageCode MatchCallback(BaseMatchData matchData)
        {
            var fmatchData = (FriendMatchData)matchData;

            if (fmatchData == null || fmatchData.ErrorCode != (int)MessageCode.Success)
            {
                return(MessageCode.MatchCreateFail);
            }
            var  friendRecord = fmatchData.FriendRecord;
            bool isFriend     = friendRecord != null;
            var  coin         = 0;
            int  intimacy     = 0;

            if (isFriend)
            {
                var oldIntimacy = friendRecord.Intimacy;
                AddFriendMatchIntimacy(friendRecord);
                intimacy = friendRecord.Intimacy - oldIntimacy;
                if (friendRecord.DayMatchCount == 1)
                {
                    //第一次比赛有奖励
                    if (fmatchData.Home.Score > fmatchData.Away.Score)
                    {
                        coin = 30;
                    }
                    else if (fmatchData.Home.Score == fmatchData.Away.Score)
                    {
                        coin = 20;
                    }
                    else
                    {
                        coin = 10;
                    }
                }
            }
            var match = new FriendMatchEntity();

            match.Idx       = fmatchData.MatchId;
            match.HomeId    = fmatchData.Home.ManagerId;
            match.HomeName  = fmatchData.Home.Name;
            match.HomeScore = fmatchData.Home.Score;
            match.AwayId    = fmatchData.Away.ManagerId;
            match.AwayName  = fmatchData.Away.Name;
            match.AwayScore = fmatchData.Away.Score;
            match.Intimacy  = intimacy;
            match.IsFriend  = isFriend;
            match.RowTime   = DateTime.Now;
            match.Status    = 0;

            MatchCore.SaveMatchStat(match.HomeId, EnumMatchType.Friend, match.HomeScore, match.AwayScore, match.HomeScore);
            var winType = EnumWinType.Win;

            if (match.HomeScore == match.AwayScore)
            {
                winType = EnumWinType.Draw;
            }
            else if (match.HomeScore < match.AwayScore)
            {
                winType = EnumWinType.Lose;
            }

            using (var transactionManager = new TransactionManager(Dal.ConnectionFactory.Instance.GetDefault()))
            {
                transactionManager.BeginTransaction();
                var trans       = transactionManager.TransactionObject;
                var messageCode = MessageCode.NbUpdateFail;
                do
                {
                    if (isFriend)
                    {
                        if (!FriendManagerMgr.Update(friendRecord, trans))
                        {
                            break;
                        }
                    }
                    if (!FriendMatchMgr.Insert(match, trans))
                    {
                        break;
                    }
                    //记录成就相关数据
                    var mess = AchievementTaskCore.Instance.UpdateFriendMatchComb(match.HomeId, winType, trans);
                    if (mess != MessageCode.Success)
                    {
                        break;
                    }

                    if (coin > 0)
                    {
                        //友谊赛金币奖励
                        var manager = ManagerCore.Instance.GetManager(fmatchData.Home.ManagerId);
                        if (manager != null)
                        {
                            mess = ManagerCore.Instance.AddCoin(manager, coin, EnumCoinChargeSourceType.FriendMatch,
                                                                ShareUtil.GenerateComb().ToString(), trans);
                            if (mess != MessageCode.Success)
                            {
                                break;
                            }
                        }
                    }
                    messageCode = MessageCode.Success;
                } while (false);
                if (messageCode == ShareUtil.SuccessCode)
                {
                    transactionManager.Commit();
                }
                else
                {
                    transactionManager.Rollback();
                }
            }
            return(MessageCode.Success);
        }