示例#1
0
 public static void TryFinish(Jackpot jackpot)
 {
     if (jackpot.EndDate <= DateTime.Now)
     {
         Finish(jackpot);
     }
 }
示例#2
0
 public BuyJackpotTicketsButtonGenerator(Member member, Jackpot jackpot, Money price, int tickets)
 {
     Member  = member;
     Jackpot = jackpot;
     Price   = price;
     Tickets = tickets;
 }
示例#3
0
        private string GetPrizeText(Jackpot jackpot)
        {
            StringBuilder sb = new StringBuilder();

            if (jackpot.AdBalancePrizeEnabled)
            {
                sb.Append("Purchase Balance: ");
                sb.Append(jackpot.AdBalancePrize.ToString());
                sb.Append(",");
            }

            if (jackpot.MainBalancePrizeEnabled)
            {
                sb.Append("Main Balance: ");
                sb.Append(jackpot.MainBalancePrize.ToString());
                sb.Append(",");
            }

            if (jackpot.LoginAdsCreditsPrizeEnabled)
            {
                sb.Append("Login Ads: ");
                sb.Append(jackpot.LoginAdsCreditsPrize.ToString());
                sb.Append(",");
            }

            if (jackpot.UpgradePrizeEnabled)
            {
                sb.Append("Upgrade: ");
                var membership = new Membership(jackpot.UpgradeIdPrize);
                sb.Append(membership.Name + " (" + jackpot.UpgradeDaysPrize + " days");
                sb.Append(",");
            }

            return(sb.ToString().TrimEnd(','));
        }
示例#4
0
    public static void BuyTickets(Jackpot jackpot, Member user, int numberOfTickets, BalanceType PurchaseBalanceType = BalanceType.PurchaseBalance)
    {
        if (!AppSettings.TitanFeatures.MoneyJackpotEnabled)
        {
            throw new MsgException("Jackpots unavailable");
        }

        var totalPrice = jackpot.TicketPrice * numberOfTickets;

        if (PurchaseBalanceType == BalanceType.PurchaseBalance && user.PurchaseBalance < totalPrice)
        {
            throw new MsgException(L1.NOTENOUGHFUNDS);
        }

        if (PurchaseBalanceType == BalanceType.CashBalance && user.CashBalance < totalPrice)
        {
            throw new MsgException(L1.NOTENOUGHFUNDS);
        }

        if (PurchaseBalanceType == BalanceType.PurchaseBalance)
        {
            user.SubtractFromPurchaseBalance(totalPrice, string.Format("Purchased {0} Jackpot tickets", numberOfTickets), BalanceLogType.Other);
        }
        else if (PurchaseBalanceType == BalanceType.CashBalance)
        {
            user.SubtractFromCashBalance(totalPrice, string.Format("Purchased {0} Jackpot tickets", numberOfTickets), BalanceLogType.Other);
        }

        user.SaveBalances();

        GiveTickets(jackpot, user, numberOfTickets);
    }
示例#5
0
    /// <summary>
    /// Returns a Dictionary that contains Winning Ticket Number and Winner Id
    /// </summary>
    /// <param name="jackpot"></param>
    /// <returns></returns>
    private static Dictionary <int, int> GetWinner(Jackpot jackpot)
    {
        var jackpotTickets = TableHelper.SelectRows <JackpotTicket>(TableHelper.MakeDictionary("JackpotId", jackpot.Id));

        if (jackpotTickets.Count <= 0)
        {
            return(null);
        }

        Random random         = new Random();
        var    winningTickets = new Dictionary <int, int>();

        for (int i = 0; i < jackpot.NumberOfWinningTickets; i++)
        {
            if (jackpotTickets.Count > 0)
            {
                var tempWinnerIndex = random.Next(0, jackpotTickets.Count);
                int winnerId        = jackpotTickets[tempWinnerIndex].UserId;
                var winningTicket   = jackpotTickets[tempWinnerIndex].Id;

                winningTickets.Add(winningTicket, winnerId);

                jackpotTickets.RemoveAt(tempWinnerIndex);
            }
        }

        return(winningTickets);
    }
示例#6
0
    private static JackpotPrize GetPrizeType(Jackpot jackpot, Member winner)
    {
        var options = new List <JackpotPrize>();

        if (jackpot.MainBalancePrizeEnabled)
        {
            options.Add(JackpotPrize.MainBalance);
        }

        if (jackpot.AdBalancePrizeEnabled)
        {
            options.Add(JackpotPrize.AdBalance);
        }

        if (jackpot.LoginAdsCreditsPrizeEnabled)
        {
            options.Add(JackpotPrize.LoginAdsCredits);
        }

        if (jackpot.UpgradePrizeEnabled && CanWinMembership(jackpot, winner))
        {
            options.Add(JackpotPrize.Upgrade);
        }

        if (options.Count == 0)
        {
            throw new MsgException("No prize available for this Jackpot.");
        }

        var random = new Random().Next(0, options.Count);

        var prize = options[random];

        return(prize);
    }
示例#7
0
        public async Task <IActionResult> Edit(int id, [Bind("JackpotID,Name,CurrentWin,TriggerPoints,CurrentTime")] Jackpot jackpot)
        {
            if (id != jackpot.JackpotID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(jackpot);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!JackpotExists(jackpot.JackpotID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(jackpot));
        }
示例#8
0
        protected void BuyJackpotTickets(Member user, Money amount, int tickets, Jackpot jackpot, string from, string transId, string cryptoCurrencyInfo)
        {
            bool successful = false;

            try
            {
                if (amount < (jackpot.TicketPrice * tickets))
                {
                    throw new MsgException("Not enough money sent!");
                }

                JackpotManager.GiveTickets(jackpot, user, tickets);

                successful = true;
            }
            catch (Exception ex)
            {
                successful = false;
                ErrorLogger.Log(ex);
            }

            PaymentProcessor PP = PaymentAccountDetails.GetFromStringType(from);

            CompletedPaymentLog.Create(PP, "Jackpot Tickets", transId, false, user.Name, amount, Money.Zero, successful, cryptoCurrencyInfo);
        }
示例#9
0
        protected override void handle(string[] args, string transactionId, string amountSent, string from, string cryptoCurrencyInfo = "")
        {
            var   user    = new Member(args[0]);
            var   jackpot = new Jackpot(Convert.ToInt32(args[1]));
            var   tickets = Int32.Parse(args[3]);
            Money amount  = Money.Parse(amountSent);

            BuyJackpotTickets(user, amount, tickets, jackpot, from, transactionId, cryptoCurrencyInfo);
        }
示例#10
0
 private static bool CanWinMembership(Jackpot jackpot, Member user)
 {
     if (!AppSettings.Points.LevelMembershipPolicyEnabled &&
         new Membership(jackpot.UpgradeIdPrize).Status == MembershipStatus.Active &&
         (user.Membership.Id == Membership.Standard.Id || user.Membership.Id == jackpot.UpgradeIdPrize))
     {
         return(true);
     }
     return(false);
 }
示例#11
0
        public async Task <IActionResult> Create([Bind("JackpotID,Name,CurrentWin,TriggerPoints,CurrentTime")] Jackpot jackpot)
        {
            if (ModelState.IsValid)
            {
                _context.Add(jackpot);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(jackpot));
        }
示例#12
0
        public Task AddJackPotAsync(Jackpot jackpot)
        => ConnectAsync(_connectionString, async connection =>
        {
            var command = new MySqlCommand(@"INSERT INTO jackpot_history (spinId,amount,dateCreated) VALUES (@spinId,@amount,@dateCreated);", connection);

            command.Parameters.AddWithValue("@spinId", jackpot.SpinId.ToString());
            command.Parameters.AddWithValue("@amount", jackpot.Amount);
            command.Parameters.AddWithValue("@dateCreated", jackpot.DateCreated);

            await command.ExecuteNonQueryAsync();
        });
示例#13
0
    private static void CreditWinner(Jackpot jackpot, JackpotWinningTicket winningTicket, Member winner)
    {
        var prizeType = GetPrizeType(jackpot, winner);

        switch (prizeType)
        {
        case JackpotPrize.MainBalance:
            var mainBalancePrize = jackpot.MainBalancePrize / jackpot.NumberOfWinningTickets;
            winner.AddToMainBalance(mainBalancePrize, "Jackpot win", BalanceLogType.Other);
            winner.SaveBalances();
            History.AddJackpotWin(winner.Name, string.Format("{0} - {1}", L1.MAINBALANCE, mainBalancePrize.ToString()), winningTicket.WinningTicketNumber.ToString(), jackpot.Name);
            PoolDistributionManager.SubtractProfit(ProfitSource.Jackpots, mainBalancePrize);
            break;

        case JackpotPrize.AdBalance:
            var adBalancePrize = jackpot.AdBalancePrize / jackpot.NumberOfWinningTickets;
            winner.AddToPurchaseBalance(adBalancePrize, "Jackpot win", BalanceLogType.Other);
            winner.SaveBalances();
            History.AddJackpotWin(winner.Name, string.Format("{0} - {1}", U6012.PURCHASEBALANCE, adBalancePrize.ToString()), winningTicket.WinningTicketNumber.ToString(), jackpot.Name);
            PoolDistributionManager.SubtractProfit(ProfitSource.Jackpots, adBalancePrize);
            break;

        case JackpotPrize.LoginAdsCredits:
            var loginAdsCreditsPrize = jackpot.LoginAdsCreditsPrize / jackpot.NumberOfWinningTickets;
            winner.AddToLoginAdsCredits(loginAdsCreditsPrize, "Jackpot win");
            winner.SaveBalances();
            History.AddJackpotWin(winner.Name, string.Format("{0} - {1}", U5008.LOGINADSCREDITS, loginAdsCreditsPrize.ToString()), winningTicket.WinningTicketNumber.ToString(), jackpot.Name);
            break;

        case JackpotPrize.Upgrade:
            var upgradeMembershipDaysPrize = jackpot.UpgradeDaysPrize / jackpot.NumberOfWinningTickets;

            if (winner.MembershipId == Membership.Standard.Id)
            {
                winner.Upgrade(new Membership(jackpot.UpgradeIdPrize), new TimeSpan(upgradeMembershipDaysPrize, 0, 0, 0));
            }
            else
            {
                winner.Upgrade(new Membership(jackpot.UpgradeIdPrize), winner.MembershipExpires.HasValue
                            ? winner.MembershipExpires.Value.AddDays(upgradeMembershipDaysPrize)
                            : AppSettings.ServerTime.AddDays(upgradeMembershipDaysPrize));
            }
            History.AddJackpotWin(winner.Name, string.Format("{0} - {1}", U5008.UPGRADED, winner.Membership.Name), winningTicket.WinningTicketNumber.ToString(), jackpot.Name);
            break;

        default: break;
        }
        JackpotTicketPrize prize = new JackpotTicketPrize();

        prize.JackpotId = jackpot.Id;
        prize.PrizeType = prizeType;
        prize.Save();
    }
示例#14
0
        public ApiJackpot(Jackpot jackpot, int userId)
        {
            id          = jackpot.Id;
            title       = jackpot.Name;
            startDate   = jackpot.StartDate;
            endDate     = jackpot.EndDate;
            ticketPrice = new ApiMoney(jackpot.TicketPrice);
            prize       = GetPrizeText(jackpot);

            participats            = jackpot.NumberOfParticipants.HasValue ? jackpot.NumberOfParticipants.Value : 0;
            allTickets             = jackpot.NumberOfTickets.HasValue ? jackpot.NumberOfTickets.Value : 0;
            yourTickets            = JackpotManager.GetNumberOfUsersTickets(jackpot.Id, userId);
            numberOfWinningTickets = 2; //Temp
        }
示例#15
0
    private UserControl GetJackpotCode(Jackpot jackpot, bool isHistory)
    {
        UserControl objControl    = (UserControl)Page.LoadControl("~/Controls/Misc/Jackpot.ascx");
        var         parsedControl = objControl as ICustomObjectControl;

        parsedControl.ObjectID = jackpot.Id;

        PropertyInfo myProp = parsedControl.GetType().GetProperty("IsHistory");

        myProp.SetValue(parsedControl, isHistory, null);

        parsedControl.DataBind();

        return(objControl);
    }
        protected override ApiResultMessage HandleRequest(object args)
        {
            string token = ((JObject)args)["token"].ToString();
            ApiJackpotTicketPurchaseData data = ((JObject)args).ToObject <ApiJackpotTicketPurchaseData>();

            int userId = ApiAccessToken.ValidateAndGetUserId(token);

            if (!AppSettings.TitanFeatures.MoneyJackpotEnabled)
            {
                throw new MsgException("Jackpot are disabled.");
            }

            Member  user    = new Member(userId);
            Jackpot jackpot = new Jackpot(data.jackpotId);

            if (data.tickets <= 0)
            {
                throw new MsgException(U5003.INVALIDNUMBEROFTICKETS);
            }

            PurchaseBalances balance       = (PurchaseBalances)data.balance;
            BalanceType      targetBalance = PurchaseOption.GetBalanceType(balance);

            var purchaseOption = PurchaseOption.Get(PurchaseOption.Features.Jackpot);

            if (balance == PurchaseBalances.Purchase && !purchaseOption.PurchaseBalanceEnabled)
            {
                throw new MsgException("You can't purchase with that balance.");
            }

            if (balance == PurchaseBalances.Cash && !purchaseOption.CashBalanceEnabled)
            {
                throw new MsgException("You can't purchase with that balance.");
            }

            JackpotManager.BuyTickets(jackpot, user, data.tickets, targetBalance);

            return(new ApiResultMessage
            {
                success = true,
                message = U5003.TICKETPURCHASESUCCESS.Replace("%n%", data.tickets.ToString()),
                data = null
            });
        }
示例#17
0
    public static void GiveTickets(Jackpot jackpot, Member user, int tickets)
    {
        if (!AppSettings.TitanFeatures.MoneyJackpotEnabled)
        {
            throw new MsgException("Jackpots unavailable");
        }

        for (int i = 0; i < tickets; i++)
        {
            JackpotTicket ticket = new JackpotTicket();
            ticket.JackpotId = jackpot.Id;
            ticket.UserId    = user.Id;
            ticket.Save();
        }

        var totalPrice = jackpot.TicketPrice * tickets;

        PoolDistributionManager.AddProfit(ProfitSource.Jackpots, totalPrice);
    }
示例#18
0
    public static void Finish(Jackpot jackpot)
    {
        try
        {
            jackpot.Status = JackpotStatus.Finished;
            Dictionary <int, int> winnerDictionary = GetWinner(jackpot);

            //Update Jackpot stats before deleting JackpotTickets data
            if (winnerDictionary != null)
            {
                foreach (var winnerData in winnerDictionary)
                {
                    JackpotWinningTicket winningTicket = new JackpotWinningTicket();
                    winningTicket.JackpotId           = jackpot.Id;
                    winningTicket.UserWinnerId        = winnerData.Value;
                    winningTicket.WinningTicketNumber = winnerData.Key;
                    winningTicket.Save();

                    //Credit winner
                    Member memberWinner = new Member((int)winningTicket.UserWinnerId);

                    CreditWinner(jackpot, winningTicket, memberWinner);
                }
            }

            jackpot.NumberOfParticipants = GetNumberOfParticipants(jackpot.Id);
            jackpot.NumberOfTickets      = GetNumberOfTickets(jackpot.Id);

            //Delete JackpotTickets data
            TableHelper.DeleteRows <JackpotTicket>(TableHelper.MakeDictionary("JackpotId", jackpot.Id));
        }
        catch (Exception ex)
        {
            ErrorLogger.Log(ex);
            throw new MsgException(ex.Message);
        }
        finally
        {
            jackpot.Status = JackpotStatus.Finished;
            jackpot.Save();
        }
    }
        public Jackpot GetJackpotBalance()
        {
            var jackpot = new Jackpot();

            if (context.Tickets.Count() > 0)
            {
                var ticketsSold = context.Tickets.Sum(i => i.TicketAmount.Ticket_Amount);
                var payouts     = context.WeeklyPlays.Sum(i => i.Payout_Amount);
                if (payouts == null)
                {
                    payouts = 0;
                }
                jackpot.JackpotBalance = (Decimal)(ticketsSold - payouts);
            }
            else
            {
                jackpot.JackpotBalance = 0;
            }
            return(jackpot);
        }
        public Jackpot GetJackpotSinceLastWin(WeeklyPlay wp)
        {
            var        jackpot = new Jackpot();
            WeeklyPlay lastWin = GetLastWeeklyPlayWin(wp);

            if (lastWin == null)
            {
                var lastStartWeek = GetLastStartWeek(wp.Play_Date);
                jackpot.JackpotBalance = (Decimal)context.Tickets.Where(i => i.Purchase_Date < lastStartWeek).Sum(i => i.TicketAmount.Ticket_Amount) - GetPreviousNonWinningPayouts(wp);
            }
            else
            {
                DateTime lastStartWeek   = GetLastStartWeek(lastWin.Play_Date);
                DateTime currentPlayWeek = GetLastStartWeek(wp.Play_Date);
                var      de = (Decimal)context.Tickets.Where(i => i.Purchase_Date > lastStartWeek && i.Purchase_Date < currentPlayWeek).Sum(i => i.TicketAmount.Ticket_Amount);
                jackpot.JackpotBalance = de - GetPreviousNonWinningPayouts(wp);
            }

            return(jackpot);
        }
示例#21
0
        static public Jackpot calculateJackpot(IEnumerable <Player> players, Team winner, Settings.GameTypes gameType, Script_Multi script, bool bTicker)
        {
            Jackpot result       = new Jackpot();
            int     fixedjackpot = 0;

            Jackpot.Reward rewards;
            int            highest = 0;

            int    pointsPerKill         = 0;
            int    pointsPerDeath        = 0;
            int    pointsPerFlag         = 0;
            double pointsPerSecondWinner = 0;
            double pointsPerSecondLoser  = 0;
            double pointsPerHP           = 0;

            int totalkills  = 0;
            int totalDeaths = 0;
            int gameLength  = 0;

            if (winner != null)
            {
                totalkills  = winner._currentGameKills;
                totalDeaths = winner._currentGameDeaths;
                gameLength  = (winner._arena._tickGameEnded - winner._arena._tickGameStarted) / 1000;
            }
            int totalHPHealed = 0;
            int totalFlagCaps = 0;

            switch (gameType)
            {
            case Settings.GameTypes.Conquest:
                fixedjackpot          = Settings.c_jackpot_CQ_Fixed;
                pointsPerKill         = Settings.c_jackpot_CQ_PointsPerKill;
                pointsPerDeath        = Settings.c_jackpot_CQ_PointsPerDeath;
                pointsPerFlag         = Settings.c_jackpot_CQ_PointsPerFlag;
                pointsPerSecondWinner = Settings.c_jackpot_CQ_WinnerPointsPerSecond;
                pointsPerSecondLoser  = Settings.c_jackpot_CQ_LoserPointsPerSecond;
                pointsPerHP           = Settings.c_jackpot_CQ_PointsPerHP;
                break;

            case Settings.GameTypes.Coop:
                fixedjackpot          = Settings.c_jackpot_Co_Fixed;
                pointsPerKill         = Settings.c_jackpot_Co_PointsPerKill;
                pointsPerDeath        = Settings.c_jackpot_Co_PointsPerDeath;
                pointsPerFlag         = Settings.c_jackpot_Co_PointsPerFlag;
                pointsPerSecondWinner = Settings.c_jackpot_Co_WinnerPointsPerSecond;
                pointsPerSecondLoser  = Settings.c_jackpot_Co_LoserPointsPerSecond;
                pointsPerHP           = Settings.c_jackpot_Co_PointsPerHP;
                break;

            case Settings.GameTypes.Royale:
                fixedjackpot          = Settings.c_jackpot_CQ_Fixed;
                pointsPerKill         = Settings.c_jackpot_CQ_PointsPerKill;
                pointsPerDeath        = Settings.c_jackpot_CQ_PointsPerDeath;
                pointsPerFlag         = Settings.c_jackpot_CQ_PointsPerFlag;
                pointsPerSecondWinner = Settings.c_jackpot_CQ_WinnerPointsPerSecond;
                pointsPerSecondLoser  = Settings.c_jackpot_CQ_LoserPointsPerSecond;
                pointsPerHP           = Settings.c_jackpot_CQ_PointsPerHP;
                break;
            }

            //Set our fixed
            result.totalJackPot += fixedjackpot;

            //Calculate MVP
            foreach (Player player in players)
            {
                rewards = new Jackpot.Reward();
                int score = 0;
                rewards.player = player;

                score += Convert.ToInt32((script.StatsCurrent(player).kills *pointsPerKill));
                score += Convert.ToInt32((script.StatsCurrent(player).deaths *pointsPerDeath));
                score += Convert.ToInt32((script.StatsCurrent(player).flagCaptures *pointsPerFlag));
                score += Convert.ToInt32((script.StatsCurrent(player).potentialHealthHealed *pointsPerHP));

                //Increment Jackpot totals
                totalHPHealed += script.StatsCurrent(player).potentialHealthHealed;
                totalFlagCaps += script.StatsCurrent(player).flagCaptures;

                //Calculate win/loss play seconds
                if (winner != null)
                {
                    if (winner._name == "Titan Militia")
                    {
                        score += Convert.ToInt32((script.StatsCurrent(player).titanPlaySeconds *pointsPerSecondWinner));
                        score += Convert.ToInt32((script.StatsCurrent(player).collectivePlaySeconds *pointsPerSecondLoser));
                    }
                    else
                    {
                        score += Convert.ToInt32((script.StatsCurrent(player).collectivePlaySeconds *pointsPerSecondWinner));
                        score += Convert.ToInt32((script.StatsCurrent(player).titanPlaySeconds *pointsPerSecondLoser));
                    }
                }

                //Tally up his overall score and check if it's our new highest
                rewards.Score    = score;
                result.totalMVP += score;
                result._playerRewards.Add(rewards);

                if (score >= highest)
                {
                    highest = score;
                }
            }

            //Calculate Total Jackpot
            result.totalJackPot += (totalkills * pointsPerKill);
            result.totalJackPot += (totalDeaths * pointsPerDeath);
            result.totalJackPot += (gameLength * 4);
            result.totalJackPot += Convert.ToInt32(totalHPHealed * pointsPerHP);
            result.totalJackPot += (totalFlagCaps * pointsPerFlag);


            //Calculate each players reward based on their MVP score and the overall jackpot
            foreach (Jackpot.Reward reward in result._playerRewards)
            {
                reward.MVP = (double)reward.Score / (double)highest;
                if (!bTicker)
                {
                    reward.points     = Convert.ToInt32(result.totalJackPot * reward.MVP);
                    reward.cash       = Convert.ToInt32(((result.totalJackPot * reward.MVP) * Settings.c_jackpot_CashMultiplier));
                    reward.experience = Convert.ToInt32((result.totalJackPot * reward.MVP) * Settings.c_jackpot_ExpMultiplier);
                }
            }
            return(result);
        }
示例#22
0
    public override void DataBind()
    {
        base.DataBind();
        user    = Member.CurrentInCache;
        Jackpot = new Jackpot(ObjectID);

        if (IsHistory)
        {
            ParticipantsLiteral.Text        = Jackpot.NumberOfParticipants.ToString();
            TicketsLiteral.Text             = Jackpot.NumberOfTickets.ToString();
            BuyTicketsPlaceholder.Visible   = false;
            UsersTicketsPlaceholder.Visible = false;
            HistoryPlaceholder.Visible      = true;

            var winners        = Jackpot.GetDistinctUserWinnerIds();
            var winningTickets = Jackpot.GetWinningTicketNumbers();

            if (winners.Count > 0 && winningTickets.Count > 0)
            {
                var sb = new StringBuilder();

                for (int i = 0; i < winners.Count; i++)
                {
                    string name = new Member((int)winners.ElementAt(i)).Name;
                    sb.Append(name);

                    if (i != winners.Count - 1)
                    {
                        sb.Append(", ");
                    }
                }

                WinnerLiteral.Text = sb.ToString();
                sb.Clear();

                for (int i = 0; i < winningTickets.Count; i++)
                {
                    string ticket = "#" + winningTickets.ElementAt(i).ToString();
                    sb.Append(ticket);

                    if (i != winningTickets.Count - 1)
                    {
                        sb.Append(", ");
                    }
                }

                WinningTicketLiteral.Text = sb.ToString();
            }
            else
            {
                WinnerLiteral.Text        = "-";
                WinningTicketLiteral.Text = "-";
            }
        }
        else
        {
            UsersTicketsPlaceholder.Visible = true;
            ParticipantsLiteral.Text        = JackpotManager.GetNumberOfParticipants(Jackpot.Id).ToString();
            TicketsLiteral.Text             = JackpotManager.GetNumberOfTickets(Jackpot.Id).ToString();
            BuyTicketsPlaceholder.Visible   = true;
            HistoryPlaceholder.Visible      = false;
            TicketList = JackpotManager.GetUsersTickets(Jackpot.Id, user.Id);
            UsersTicketsLiteral.Text = string.Empty;
            StringBuilder sb = new StringBuilder();
            foreach (var ticket in TicketList)
            {
                sb.Append(string.Format("#{0}, ", ticket.Id.ToString()));
            }
            //remove comma
            if (sb.Length > 2)
            {
                sb.Remove(sb.Length - 2, 2);
            }
            else
            {
                sb.Append("-");
            }
            UsersTicketsLiteral.Text = sb.ToString();

            LangAdder.Add(BuyTicketsFromAdBalanceButton, U6012.PAYVIAPURCHASEBALANCE);
            LangAdder.Add(BuyTicketsFromCashBalanceButton, U6005.PAYVIACASHBALANCE);
            LangAdder.Add(BuyTicketsViaPaymentProcessor, U6005.PAYVIAPAYMENTPROCESSOR);

            NumberOfTicketsLiteral.Text = TicketList.Count.ToString();
        }

        HidePrize();
    }
示例#23
0
 public static JackpotHistoryDto Create(Jackpot jackpot)
 => new JackpotHistoryDto
 {
     Amount      = jackpot.Amount,
     DateCreated = jackpot.DateCreated
 };
        public IHttpActionResult UpdateJackpot(Jackpot jackpot)
        {
            if (jackpot.Points < 1)
            {
                // Error
                jackpot.Status = JackpotStatus.InvalidPoints;
                return(Ok(jackpot));
            }

            var user = _database.Users.Where(x => x.DiscordId == jackpot.DiscordId).FirstOrDefault();

            if (user == null)
            {
                // Error
                jackpot.Status = JackpotStatus.UserDoesntExist;
                return(Ok(jackpot));
            }

            jackpot.User = user;

            if (jackpot.Points > user.Points)
            {
                // Error
                jackpot.Status = JackpotStatus.UserNotEnoughPoints;
                return(Ok(jackpot));
            }

            var  allJackpots = _database.Jackpot.ToList();
            long totalPoints = jackpot.Points;

            for (int i = 0; i < allJackpots.Count; i++)
            {
                totalPoints += allJackpots[i].Points;
            }

            var existingJackpot = _database.Jackpot.Where(x => x.UserId == user.Id).FirstOrDefault();

            user.Points -= jackpot.Points;
            // New
            if (existingJackpot == null)
            {
                jackpot.UserId = user.Id;
                _database.Jackpot.Add(jackpot);
                _database.Context.SaveChanges();
                jackpot.WinChancePercentage = Math.Round((double)jackpot.Points / totalPoints * 100.00F, 2);
                jackpot.TotalPoints         = totalPoints;

                return(Ok(jackpot));
            }
            // Existing
            else
            {
                existingJackpot.Points += jackpot.Points;
                existingJackpot.UserId  = user.Id;
                existingJackpot.User    = user;
                existingJackpot.WinChancePercentage = Math.Round((double)existingJackpot.Points / totalPoints * 100.00F, 2);
                existingJackpot.TotalPoints         = totalPoints;
                _database.Context.SaveChanges();

                return(Ok(existingJackpot));
            }
        }