protected void ReorderIds() { LeadershipRank prev = null; LeadershipRank next = null; if (this.PrevRankId.HasValue && this.PrevRankId.Value != -1) { prev = new LeadershipRank(this.PrevRankId.Value); } if (this.NextRankId.HasValue && this.NextRankId.Value != -1) { next = new LeadershipRank(this.NextRankId.Value); } if (prev != null && next != null) { prev.NextRankId = next.Id; next.PrevRankId = prev.Id; prev.Save(); next.Save(); } else if (prev != null && next == null) //Delete Last { prev.NextRankId = -1; prev.Save(); } else if (prev == null && next != null) //Delete First { next.PrevRankId = -1; next.Save(); } }
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); } }
public void RemoveRank(int rankId, int rankNumber) { var rank = new LeadershipRank(rankId); if (rank != null) { rank.Delete(); } }
/// <summary> /// Returns last rank /// </summary> /// <returns></returns> public static LeadershipRank GetLast() { LeadershipRank result = LeadershipRank.RankList.FirstOrDefault(x => !x.NextRankId.HasValue || x.NextRankId.Value == -1); if (result != null && result.Status != UniversalStatus.Active) { result = result.GetPrev(); } return(result); }
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); } }
public static void CheckRequirementForRanks() { if (!IsRestrictionForEachRank()) { var querry = string.Format(@"SELECT * FROM {0} WHERE {1} NOT IN (SELECT {2} FROM {3})", LeadershipRank.TableName, LeadershipRank.Columns.Id, LeadershipRankRequirements.Columns.Rank, LeadershipRankRequirements.TableName); var rankList = TableHelper.GetListFromRawQuery <LeadershipRank>(querry); LeadershipRank.DeleteRange(rankList); } }
public RanksUsers() : base() { LeadershipRank first = LeadershipRank.GetFirst(); if (first != null) { UserId = Member.CurrentId; RankId = first.Id; AquairedDate = DateTime.Now; IsCurrent = true; } }
public static LeadershipRank GetMaxUserRank(int userId) { LeadershipRank result = null; List <LeadershipRank> list = GetUserRanks(userId); if (list.Count > 0) { result = list.FirstOrDefault(x => x.Rank == list.Max(y => y.Rank)); } return(result); }
/// <summary> /// Returns previously Active rank /// </summary> /// <returns></returns> public LeadershipRank GetPrev() { LeadershipRank result = null; if (this.PrevRankId.HasValue && this.PrevRankId.Value != -1) { result = new LeadershipRank(this.PrevRankId.Value); if (result.Status != UniversalStatus.Active) { result = result.GetPrev(); } } return(result); }
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(); } }
private void SetRankIds() { LeadershipRank row = LeadershipRank.GetLast(); if (row != null) { Rank = row.Rank + 1; PrevRankId = row.Id; row.NextRankId = TableHelper.GetNextId(TableName); row.Save(); } else { Rank = 1; PrevRankId = -1; NextRankId = -1; } }
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); } }
public static void CheckSystem(List <RestrictionKind> restriction, Member user, int checkReferrerLevels = 0) { if (!AppSettings.TitanFeatures.LeaderShipSystemEnabled) { return; } var list = LeadershipRankRequirements.RequirementsList; for (int i = 0; i < list.Count; i++) { if (restriction.Contains(list[i].RestrictionKind)) { CheckRankUpDown(user); if (checkReferrerLevels > 0 && user.HasReferer && LeadershipRankRequirements.HaveToCheckDirectReferral()) { CheckRankUpDown(new Member(user.ReferrerId), --checkReferrerLevels); } break; } } LeadershipRank.DeletePausedIfPossible(); }
public void MoveRankUp() { if (!this.PrevRankId.HasValue || this.PrevRankId.Value == -1) { return; } LeadershipRank rankSwap = new LeadershipRank(this.PrevRankId.Value); this.Rank ^= rankSwap.Rank; rankSwap.Rank ^= this.Rank; this.Rank ^= rankSwap.Rank; this.PrevRankId = rankSwap.PrevRankId; rankSwap.PrevRankId = this.Id; rankSwap.NextRankId = this.NextRankId; this.NextRankId = rankSwap.Id; if (this.PrevRankId.HasValue && this.PrevRankId.Value != -1) { LeadershipRank rankLower = new LeadershipRank(this.PrevRankId.Value); rankLower.NextRankId = this.Id; rankLower.Save(); } if (rankSwap.NextRankId.HasValue && rankSwap.NextRankId.Value != -1) { LeadershipRank rankHigher = new LeadershipRank(rankSwap.NextRankId.Value); rankHigher.PrevRankId = rankSwap.Id; rankHigher.Save(); } this.Save(); rankSwap.Save(); }
/// <summary> /// Only used for auto-delete when rank do not have requirement /// </summary> /// <param name="list"></param> public static void DeleteRange(List <LeadershipRank> list) { LeadershipRank prev = null; LeadershipRank next = null; bool prevSaveDB = false; bool nextSaveDB = false; foreach (LeadershipRank rank in list) { if (rank.PrevRankId.HasValue && rank.PrevRankId.Value != -1) { prev = list.FirstOrDefault(x => x.Id == rank.PrevRankId.Value) ?? new LeadershipRank(rank.PrevRankId.Value); prevSaveDB = !list.Any(x => x.Id == prev.Id); } if (rank.NextRankId.HasValue && rank.NextRankId.Value != -1) { next = list.FirstOrDefault(x => x.Id == rank.NextRankId.Value) ?? new LeadershipRank(rank.NextRankId.Value); nextSaveDB = !list.Any(x => x.Id == next.Id); } if (prev != null && next != null) { prev.NextRankId = rank.NextRankId; next.PrevRankId = rank.PrevRankId; if (prevSaveDB) { prev.Save(); } if (nextSaveDB) { next.Save(); } } else if (prev != null && next == null) //Delete Last { prev.NextRankId = -1; if (prevSaveDB) { prev.Save(); } } else if (prev == null && next != null) //Delete First { next.PrevRankId = -1; if (nextSaveDB) { next.Save(); } } TableHelper.DeleteRows(TableName, Columns.Id, rank.Id); prevSaveDB = false; nextSaveDB = false; } UpdateRanksOrder(); }
public void AddRank(string name, PrizeKind prize, string prizeValue, string note = null) { var newRank = new LeadershipRank(name, prize, prizeValue, note); newRank.Save(); }
public void EditRank(int Id) { var rank = new LeadershipRank(Id); }