예제 #1
0
        public async Task <List <BetModel> > GetBets()
        {
            try
            {
                var bets = await _betRepository.GetBets();

                return(bets.Select(u => new BetModel
                {
                    Id = u.Id,
                    Date = u.Date,
                    Stake = u.Stake.ToString(),
                    Odd = u.ODD.ToString(),
                    Green = u.Green,
                    Lucro = u.Lucro.ToString(),
                    SaldoAtual = u.SaldoAtual.ToString(),
                    Porcentagem = u.Porcentagem.ToString()
                }).ToList());
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);

                return(null);
            }
        }
예제 #2
0
        public async Task <IActionResult> GetBets()
        {
            var betsResources = await betRepository.GetBets();

            ViewBag.Currency = await currencyRepository.GetCurrency();

            return(View("Bets", betsResources));
        }
예제 #3
0
        public Task <HttpResponseMessage> GetBets(int userId, [FromUri] string skip, [FromUri] string take, [FromUri] string orderBy, [FromUri] string filter = "none")
        {
            string token = Request.Headers.GetValues("DiceGaming-Token").FirstOrDefault();

            if (!loginRepository.HasUserAndToken(userId, token))
            {
                throw new ForbiddenException();
            }

            int skipNum;

            if (!int.TryParse(skip, out skipNum))
            {
                throw new BadRequestException();
            }

            int takeNum;

            if (!int.TryParse(take, out takeNum))
            {
                throw new BadRequestException();
            }

            if (skipNum < 0 || takeNum < 0)
            {
                throw new BadRequestException();
            }

            if (!object.Equals(orderBy, "time") &&
                !object.Equals(orderBy, "win"))
            {
                throw new BadRequestException();
            }

            if (!object.Equals(filter, "win") &&
                !object.Equals(filter, "lose") &&
                !object.Equals(filter, "none"))
            {
                throw new BadRequestException();
            }

            var bets = betRepository.GetBets(userId, skipNum, takeNum, orderBy, filter);

            return(Task.FromResult(Request.CreateResponse(HttpStatusCode.OK, from b in bets
                                                          select new
            {
                CreationDate = b.CreationDate,
                Stake = b.Stake,
                Win = b.Win
            })));
        }
예제 #4
0
        public async Task <bool> UpdateSeason()
        {
            var season = await IsSelected();

            var bets = await _betRepository.GetBets();

            var teams = await _teamRepository.GetTeams();

            season.Teams  = teams.Count();
            season.Bets   = bets.Count();
            season.Profit = Math.Round(bets.Sum(x => x.Profit) - bets.Sum(x => x.Match.Stake), 2);

            return(await _context.SaveChangesAsync() > 0);
        }
예제 #5
0
        public async Task <Statistics> Statistics()
        {
            var listBets = await betRepository.GetBets();

            var statistics = new Statistics();

            if (listBets.Any())
            {
                statistics.TotalMatches  = listBets.Count();
                statistics.TotalWon      = listBets.Where(x => x.Won == true).Count();
                statistics.TotalBet      = listBets.Sum(x => x.Match.Stake);
                statistics.TotalEarn     = listBets.Sum(x => x.Profit);
                statistics.WonPercentage = Math.Truncate((double)statistics.TotalWon / (double)statistics.TotalMatches * 100);
                statistics.Profit        = Math.Round(statistics.TotalEarn - statistics.TotalBet, 2);
                statistics.MaxStake      = listBets.Max(x => x.Match.Stake);
                statistics.MaxOdd        = listBets.Any(x => x.Won == true) ?
                                           listBets.Where(x => x.Won == true).Max(x => x.Match.Odd) : 0;
                statistics.MaxReturn = listBets.Any(x => x.Won == true) ?
                                       listBets.Where(x => x.Won == true).Max(x => x.Profit) : 0;

                // getting the weeks to display weekly profit
                int weeks = 1;

                if (listBets.Any())
                {
                    var firstBet = listBets.First();
                    var lastBet  = listBets.Last();
                    weeks = Convert.ToInt32((lastBet.Match.Date - firstBet.Match.Date).TotalDays / 7);
                    weeks = weeks > 1 ? weeks : 1;
                }

                statistics.WeeklyProfit = (int)Math.Truncate(statistics.Profit / weeks);
            }

            return(statistics);
        }
        public async Task Run([TimerTrigger("55 23 * * *")] TimerInfo myTimer, ILogger log)
        {
            log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");

            var allBets = await _betRepository.GetBets();

            var betsEndingToday = allBets.Where(x => x.Date.Date == DateTime.Today);

            log.LogInformation($"Found {betsEndingToday.Count()} ending today");

            int firstP  = 3;
            int secondP = 2;
            int thirdP  = 1;

            foreach (var bet in betsEndingToday)
            {
                var price = await _coinGeckoAPIService.GetBtcPrice();

                var userbets = new List <PlacedBet>();
                userbets.AddRange(bet.PlacedBets);

                if (price != null && userbets.Count >= 3)
                {
                    //Find winner
                    var usd          = price.Bitcoin.Usd;
                    var firstUserBet = userbets.Aggregate((x, y) => Math.Abs(x.Price - usd) < Math.Abs(y.Price - usd) ? x : y);

                    //Find second place
                    userbets.Remove(firstUserBet);
                    var secondUserBet = userbets.Aggregate((x, y) => Math.Abs(x.Price - usd) < Math.Abs(y.Price - usd) ? x : y);

                    //Find third place
                    userbets.Remove(secondUserBet);
                    var thirdUserBet = userbets.Aggregate((x, y) => Math.Abs(x.Price - usd) < Math.Abs(y.Price - usd) ? x : y);


                    var firstUser = await _userBetRepository.GetUserBet(firstUserBet.BetUserId);

                    var secondUser = await _userBetRepository.GetUserBet(secondUserBet.BetUserId);

                    var thirdUser = await _userBetRepository.GetUserBet(thirdUserBet.BetUserId);

                    await UpdateUser(firstUserBet, firstP, 1, firstUser);
                    await UpdateUser(secondUserBet, secondP, 2, secondUser);
                    await UpdateUser(thirdUserBet, thirdP, 3, thirdUser);

                    StringBuilder sb = new StringBuilder();

                    sb.AppendLine($"Bet Name: **{bet.ShortName}**");
                    sb.AppendLine($"BTC Price: **${usd}**");
                    sb.AppendLine($"First Place: **{firstUserBet.Name}** | Bet: **{firstUserBet.Price}** | Points: **{firstP}**");
                    sb.AppendLine($"Second Place: **{secondUserBet.Name}** | Bet: **{secondUserBet.Price}** | Points: **{secondP}**");
                    sb.AppendLine($"Third Place: **{thirdUserBet.Name}** | Bet: **{thirdUserBet.Price}** | Points: **{thirdP}**");

                    var announceWinner = await _discordWebhookService.PostWinners(new DiscordMessage { Username = "******", AvatarUrl = "", Content = null, Embeds = new List <Embeds> {
                                                                                                           new Embeds {
                                                                                                               Color = "13938487", Title = "Bet winners", Description = sb.ToString()
                                                                                                           }
                                                                                                       } });

                    if (announceWinner)
                    {
                        log.LogInformation($"Published winners");
                    }
                    else
                    {
                        log.LogInformation("Failed to publsh events");
                    }
                }
            }

            log.LogInformation("App finished");
        }
예제 #7
0
 public IQueryable <BetSlip> GetBets()
 {
     return(_betRepository.GetBets());
 }