Esempio n. 1
0
        private static void CheckRankUpDown(Member user, int checkReferrerLevels = 0)
        {
            if (!AppSettings.TitanFeatures.LeaderShipSystemEnabled)
            {
                return;
            }

            RanksUsers currentRank = RanksUsers.GetCurrentUserRank(user.Id);
            int        newRankId   = -1;

            LeadershipRank rank = null;

            if (currentRank == null)
            {
                rank = LeadershipRank.GetFirst();

                if (rank != null && LeadershipRank.IsRankAccured(rank.Id, user))
                {
                    RanksUsers.UpdateRank(rank.Id, user.Id);
                    currentRank = RanksUsers.GetByRankId(user.Id, rank.Id);
                }
                else
                {
                    return;
                }
            }

            rank = new LeadershipRank(currentRank.RankId);
            if (!LeadershipRank.IsRankAccured(rank.Id, user))
            {
                newRankId = CheckRankDown(user, rank);
            }
            else
            {
                newRankId = CheckRankUp(user, rank);
            }

            RanksUsers newRank = RanksUsers.GetByRankId(user.Id, newRankId);

            if (newRank != null)
            {
                newRank.SetCurrent();
            }
            else
            {
                RanksUsers.SetRankZero(user.Id);
            }

            if (checkReferrerLevels > 0 && user.HasReferer && LeadershipRankRequirements.HaveToCheckDirectReferral())
            {
                CheckRankUpDown(new Member(user.ReferrerId), --checkReferrerLevels);
            }
        }
Esempio n. 2
0
        public static void UpdateRank(int newRankId, int userId)
        {
            RanksUsers currentRank = RanksUsers.GetCurrentUserRank(userId);

            if (currentRank == null || currentRank.RankId != newRankId)
            {
                currentRank = GetOrCreateRanksUsers(userId, newRankId);
                List <RanksUsers> userRanks = GetRanksUsers(userId);
                if (!userRanks.Any(x => x.RankId == currentRank.RankId))
                {
                    LeadershipRank.GivePrize(currentRank.RankId, new Member(userId));
                }

                currentRank.Save();
            }
        }