Ejemplo n.º 1
0
        public static void AddAndClean(ContestType Type, string w1, string w2, string w3)
        {
            //Check if there is something to clean
            int count = TableHelper.CountOf <ContestLatestWinners>(TableHelper.MakeDictionary("Type", (int)Type));

            if (count > 0)
            {
                //Yes
                TableHelper.DeleteRows <ContestLatestWinners>(TableHelper.MakeDictionary("Type", (int)Type));
            }

            ContestLatestWinners temp = new ContestLatestWinners();

            temp.Type    = Type;
            temp.Winner1 = w1;
            temp.Winner2 = w2;
            temp.Winner3 = w3;
            temp.Save();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Finishes the contest, no need to save
        /// </summary>
        public void Finish()
        {
            try
            {
                this.Status = ContestStatus.Finished;

                //Pick up the winners
                //var AllParticipants = TableHelper.SelectRows<ContestParticipant>
                //   (TableHelper.MakeDictionary("ContestId", this.Id));
                var AllParticipants = GetAllMembersParticipating();

                AllContestLatestWinners HistoryContestData = new AllContestLatestWinners();
                HistoryContestData.ContestId            = this.Id;
                HistoryContestData.NumberOfParticipants = AllParticipants.Count;

                AllParticipants.Sort(Comparison);

                string winner1 = "-";
                string winner2 = "-";
                string winner3 = "-";

                if (AllParticipants.Count > 0)
                {
                    winner1 = "OK";
                }
                if (AllParticipants.Count > 1)
                {
                    winner2 = "OK";
                }
                if (AllParticipants.Count > 2)
                {
                    winner3 = "OK";
                }

                Money ZeroMoney = new Money(0);

                if (winner1 == "OK")
                {
                    if (AllParticipants[0].Points == ZeroMoney)
                    {
                        winner1 = "-";
                    }
                    else
                    {
                        Member Winner1 = new Member(AllParticipants[0].Username);
                        ContestManager.AwardMember(Winner1, this.RewardType, this.Prize1Value, 1);
                        winner1 = Winner1.Name + ": " + ContestManager.GetPrizeProperObject(this.RewardType, this.Prize1Value).ToString() + " [%" + (int)this.RewardType + "%]";
                    }
                }
                if (winner2 == "OK")
                {
                    if (AllParticipants[1].Points == ZeroMoney)
                    {
                        winner2 = "-";
                    }
                    else
                    {
                        Member Winner2 = new Member(AllParticipants[1].Username);
                        ContestManager.AwardMember(Winner2, this.RewardType, this.Prize2Value, 2);
                        winner2 = Winner2.Name + ": " + ContestManager.GetPrizeProperObject(this.RewardType, this.Prize2Value).ToString() + " [%" + (int)this.RewardType + "%]";
                    }
                }
                if (winner3 == "OK")
                {
                    if (AllParticipants[2].Points == ZeroMoney)
                    {
                        winner3 = "-";
                    }
                    else
                    {
                        Member Winner3 = new Member(AllParticipants[2].Username);
                        ContestManager.AwardMember(Winner3, this.RewardType, this.Prize3Value, 3);
                        winner3 = Winner3.Name + ": " + ContestManager.GetPrizeProperObject(this.RewardType, this.Prize3Value).ToString() + " [%" + (int)this.RewardType + "%]";
                    }
                }

                //Save contest history data
                foreach (var elem in AllParticipants)
                {
                    HistoryContestData.Participants += elem.Username + "(" + elem.Points.GetRealTotals().ToString() + "), ";
                }
                HistoryContestData.Winner1 = winner1;
                HistoryContestData.Winner2 = winner2;
                HistoryContestData.Winner3 = winner3;
                HistoryContestData.Save();

                ContestLatestWinners.AddAndClean(this.Type, winner1, winner2, winner3);
                this.Save();

                //Clean the contest data (ContestParticipants)
                TableHelper.DeleteRows <ContestParticipant>(TableHelper.MakeDictionary("ContestId", this.Id));
            }
            catch (Exception ex)
            {
                ErrorLogger.Log(ex);
            }
        }