private static int CheckRankUp(Member user, LeadershipRank rank) { if (rank.NextRankId.HasValue && rank.NextRankId.Value != -1) { LeadershipRank nextRank = new LeadershipRank(rank.NextRankId.Value); if (nextRank.Status != UniversalStatus.Active || LeadershipRank.IsRankAccured(nextRank.Id, user)) { if (nextRank.Status == UniversalStatus.Active) { RanksUsers.UpdateRank(nextRank.Id, user.Id); } return(CheckRankUp(user, nextRank)); } else if (rank.Status != UniversalStatus.Active) { return(CheckRankDown(user, rank)); } else { return(rank.Id); } } else if (rank.Status != UniversalStatus.Active) { return(CheckRankDown(user, rank)); } else { return(rank.Id); } }
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); } }
private static int CheckRankDown(Member user, LeadershipRank rank) { if (rank.PrevRankId.HasValue && rank.PrevRankId.Value != -1) { LeadershipRank prevRank = new LeadershipRank(rank.PrevRankId.Value); if (prevRank.Status != UniversalStatus.Active || !LeadershipRank.IsRankAccured(prevRank.Id, user)) { return(CheckRankDown(user, prevRank)); } else { return(rank.PrevRankId.Value); } } else { return(-1); } }