Пример #1
0
 private string GeneratePrizeCode(Money Value)
 {
     return(" <b>" + ContestManager.GetPrizeProperObject(RewardType, Value).ToString() + "</b> ["
            + ContestManager.GetPrizeName(RewardType) + "]");
 }
Пример #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);
            }
        }