コード例 #1
0
        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();
            }
        }
コード例 #2
0
        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);
            }
        }
コード例 #3
0
        public void RemoveRank(int rankId, int rankNumber)
        {
            var rank = new LeadershipRank(rankId);

            if (rank != null)
            {
                rank.Delete();
            }
        }
コード例 #4
0
        /// <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);
        }
コード例 #5
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);
            }
        }
コード例 #6
0
        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);
            }
        }
コード例 #7
0
        public RanksUsers() : base()
        {
            LeadershipRank first = LeadershipRank.GetFirst();

            if (first != null)
            {
                UserId       = Member.CurrentId;
                RankId       = first.Id;
                AquairedDate = DateTime.Now;
                IsCurrent    = true;
            }
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        /// <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);
        }
コード例 #10
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();
            }
        }
コード例 #11
0
        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;
            }
        }
コード例 #12
0
        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);
            }
        }
コード例 #13
0
        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();
        }
コード例 #14
0
        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();
        }
コード例 #15
0
        /// <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();
        }
コード例 #16
0
        public void AddRank(string name, PrizeKind prize, string prizeValue, string note = null)
        {
            var newRank = new LeadershipRank(name, prize, prizeValue, note);

            newRank.Save();
        }
コード例 #17
0
 public void EditRank(int Id)
 {
     var rank = new LeadershipRank(Id);
 }