Exemplo n.º 1
0
        public void GenerateResult(UpcomingMatch match)
        {
            teamservice = new TeamService();
            betservice  = new BetService();

            Random random = new Random();

            int scoreHome = random.Next(0, 5);
            int scoreAway = random.Next(0, 5);

            MatchResult result;

            if (scoreHome > scoreAway)
            {
                result = MatchResult.HomeTeam;
            }
            else if (scoreHome < scoreAway)
            {
                result = MatchResult.AwayTeam;
            }
            else
            {
                result = MatchResult.Draw;
            }

            FinishedMatch finishedmatch = new FinishedMatch(match.MatchID, match.HomeTeam, match.AwayTeam, match.MultiplierHome,
                                                            match.MultiplierAway, match.MultiplierDraw, match.Date, scoreHome, scoreAway, result);

            matchrep.Update(finishedmatch);
            teamservice.CalculatePoints(finishedmatch);
            betservice.Payout(finishedmatch);
        }
Exemplo n.º 2
0
        public ActionResult GetSelectedMatch(int count)
        {
            UpcomingMatch match = (UpcomingMatch)TempData["Match" + count];

            Session["SelectedMatch"] = match;
            return(RedirectToAction("Create", "Bet"));
        }
Exemplo n.º 3
0
        public ActionResult FinishMatch(int count)
        {
            UpcomingMatch match = (UpcomingMatch)TempData["Match" + count];

            matchService.GenerateResult(match);
            return(RedirectToAction("FinishedMatches", "Match"));
        }
Exemplo n.º 4
0
        public ActionResult Create(BetViewModel bet)
        {
            bool   status = false;
            string message;

            User          loggedinUser = (User)Session["LoggedInUser"];
            UpcomingMatch match        = (UpcomingMatch)Session["SelectedMatch"];
            UserService   userservice  = new UserService();

            if (ModelState.IsValid)
            {
                if (bet.Amount > 5)
                {
                    if (bet.Amount < loggedinUser.Balance)
                    {
                        Bet newbet = new Bet()
                        {
                            UserID     = loggedinUser.UserID,
                            MatchID    = match.MatchID,
                            Prediction = bet.Prediction,
                            Amount     = bet.Amount
                        };

                        status = betservice.CreateBet(newbet);
                        if (status == true)
                        {
                            message = "Bet succesfully placed!";
                            userservice.RemoveFunds(loggedinUser, newbet.Amount);
                        }
                        else
                        {
                            message = "Database Error!";
                        }
                    }
                    else
                    {
                        message = "Not enough funds to make this bet.";
                    }
                }
                else
                {
                    message = "Bet amount must be higher than 5,- or try to use a comma.";
                }
            }
            else
            {
                message = "Invalid request.";
            }

            ViewBag.Status  = status;
            ViewBag.Message = message;

            return(View(bet));
        }
Exemplo n.º 5
0
        public ActionResult Create(MatchViewModel match)
        {
            bool   status = false;
            string message;

            int hometeamID = match.HomeTeamID;
            int awayteamID = match.AwayTeamID;

            if (hometeamID != 0 && awayteamID != 0 && hometeamID != awayteamID)
            {
                if (match.MultiplierTeamHome > 1 && match.MultiplierTeamAway > 1 && match.MultiplierDraw > 1)
                {
                    UpcomingMatch newMatch = new UpcomingMatch(hometeamID, awayteamID, match.MultiplierTeamHome, match.MultiplierTeamAway, match.MultiplierDraw, match.Date);
                    status = matchService.CreateMatch(newMatch);

                    if (status == true)
                    {
                        message = "Match created successfully!";
                    }
                    else
                    {
                        message = "Match could not be created.";
                    }
                }
                else
                {
                    message = "Multipliers are invalid! The values must be greater than and decimals must be separated with a comma.";
                }
            }
            else
            {
                message = "Select 2 different teams.";
            }

            teamservice    = new TeamService();
            match.TeamList = teamservice.GetTeams();

            ViewBag.Status  = status;
            ViewBag.Message = message;

            return(View(match));
        }
Exemplo n.º 6
0
        public List <UpcomingMatch> GetUpcomingMatches(int isFinished)
        {
            teamrep = new TeamRepository();
            List <UpcomingMatch> matchList = new List <UpcomingMatch>();

            MySqlCommand command = new MySqlCommand("GetMatches");

            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.Add("@isFinished", MySqlDbType.Binary).Value = isFinished;

            MySqlDataReader reader = database.Read(command);

            while (reader.Read())
            {
                int matchID = (int)reader["MatchID"];

                Team homeTeam = new Team();
                Team awayTeam = new Team();

                homeTeam.TeamID = (int)reader["HomeTeamID"];
                awayTeam.TeamID = (int)reader["AwayTeamID"];
                decimal  multiplierHome = (decimal)reader["MultiplierHome"];
                decimal  multiplierAway = (decimal)reader["MultiplierAway"];
                decimal  multiplierDraw = (decimal)reader["MultiplierDraw"];
                DateTime date           = (DateTime)reader["Date"];

                UpcomingMatch match = new UpcomingMatch(matchID, homeTeam, awayTeam, multiplierHome, multiplierAway, multiplierDraw, date);

                matchList.Add(match);
            }

            database.CloseConnection();

            //Hier worden de namen van de teams uit de database gehaald en in de lijst geplaatst.
            foreach (UpcomingMatch m in matchList)
            {
                m.HomeTeam.TeamName = teamrep.GetName(m.HomeTeam.TeamID);
                m.AwayTeam.TeamName = teamrep.GetName(m.AwayTeam.TeamID);
            }
            return(matchList);
        }
Exemplo n.º 7
0
        public ActionResult Create()
        {
            User loggedInUser = (User)Session["LoggedInUser"];

            UpcomingMatch match = (UpcomingMatch)Session["SelectedMatch"];

            bool betExists = betservice.CheckIfBetExists(match.MatchID, loggedInUser.UserID);

            if (betExists == false)
            {
                BetViewModel newbet = new BetViewModel
                {
                    Match = match
                };

                return(View(newbet));
            }
            else
            {
                return(RedirectToAction("UpcomingMatches", "Match"));
            }
        }
Exemplo n.º 8
0
        public UpcomingMatch GetUpcomingMatch(int matchID)
        {
            teamrep = new TeamRepository();

            DateTime date           = Convert.ToDateTime("01-01-1900");
            Team     homeTeam       = new Team();
            Team     awayTeam       = new Team();
            decimal  multiplierHome = 0;
            decimal  multiplierAway = 0;
            decimal  multiplierDraw = 0;

            MySqlCommand command = new MySqlCommand("GetMatch");

            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.Add("@matchID", MySqlDbType.Int32).Value = matchID;

            MySqlDataReader reader = database.Read(command);

            while (reader.Read())
            {
                homeTeam.TeamID = (int)reader["HomeTeamID"];
                awayTeam.TeamID = (int)reader["AwayTeamID"];
                multiplierHome  = (decimal)reader["MultiplierHome"];
                multiplierAway  = (decimal)reader["MultiplierAway"];
                multiplierDraw  = (decimal)reader["MultiplierDraw"];
                date            = (DateTime)reader["Date"];
            }

            database.CloseConnection();

            homeTeam.TeamName = teamrep.GetName(homeTeam.TeamID);
            awayTeam.TeamName = teamrep.GetName(awayTeam.TeamID);

            UpcomingMatch match = new UpcomingMatch(matchID, homeTeam, awayTeam, multiplierHome, multiplierAway, multiplierDraw, date);

            return(match);
        }
Exemplo n.º 9
0
        private static List <UpcomingMatch> ParseMatchesPage(Task <HttpResponseMessage> response)
        {
            var    content     = response.Result.Content;
            string htmlContent = content.ReadAsStringAsync().Result;

            HtmlDocument html = new HtmlDocument();

            html.LoadHtml(htmlContent);

            HtmlNode document = html.DocumentNode;

            var upcomingMatchNodes = document.QuerySelectorAll(".upcoming-match");

            List <UpcomingMatch> upcomingMatches = new List <UpcomingMatch>();

            foreach (HtmlNode upcomingMatchNode in upcomingMatchNodes)
            {
                try
                {
                    UpcomingMatch model = new UpcomingMatch();

                    //Match ID
                    string matchPageUrl = upcomingMatchNode.Attributes["href"].Value;
                    model.Id = int.Parse(matchPageUrl.Split('/', StringSplitOptions.RemoveEmptyEntries)[1]);

                    //Match date
                    long unixDateMilliseconds = long.Parse(upcomingMatchNode.Attributes["data-zonedgrouping-entry-unix"].Value);
                    model.Date = DateTimeFromUnixTimestampMillis(unixDateMilliseconds);

                    //Event ID and name
                    Event  eventModel    = new Event();
                    string eventImageUrl = upcomingMatchNode.QuerySelector(".event-logo").Attributes["src"].Value;
                    eventModel.Id   = int.Parse(eventImageUrl.Split("/").Last().Split(".").First());
                    eventModel.Name = upcomingMatchNode.QuerySelector(".event-name").InnerText;
                    model.Event     = eventModel;

                    //Number of stars
                    model.Stars = upcomingMatchNode.QuerySelectorAll(".stars i").Count();

                    var teamNodes       = upcomingMatchNode.QuerySelectorAll(".team-cell").ToList();
                    var resultScoreNode = upcomingMatchNode.QuerySelector(".result-score");

                    //Team 1 ID and name
                    Team   team1Model   = new Team();
                    string team1LogoUrl = teamNodes[0].QuerySelector("img").Attributes["src"].Value;
                    team1Model.Id   = int.Parse(team1LogoUrl.Split('/').Last());
                    team1Model.Name = teamNodes[0].QuerySelector("img").Attributes["alt"].Value;
                    model.Team1     = team1Model;

                    //Team 2 ID and name
                    Team   team2Model   = new Team();
                    string team2LogoUrl = teamNodes[1].QuerySelector("img").Attributes["src"].Value;
                    team2Model.Id   = int.Parse(team1LogoUrl.Split('/').Last());
                    team2Model.Name = teamNodes[1].QuerySelector("img").Attributes["alt"].Value;
                    model.Team2     = team2Model;

                    //Map and format
                    string mapText = upcomingMatchNode.QuerySelector(".map-text").InnerText;
                    if (mapText.Contains("bo"))
                    {
                        model.Format = mapText;
                    }
                    else
                    {
                        model.Format = "bo1";
                        model.Map    = MapSlug.MapSlugs[mapText];
                    }

                    upcomingMatches.Add(model);
                }
                catch (Exception)
                {
                }
            }
            return(upcomingMatches);
        }
        private List <UpcomingMatch> MapUpcomingMatch(JToken content)
        {
            List <UpcomingMatch> upcomingGames = new List <UpcomingMatch>();

            foreach (var item in content)
            {
                if (!item["opponents"].HasValues)
                {
                    System.Diagnostics.Debug.WriteLine("Array is empty");
                    continue;
                }
                else if (item["opponents"].Count <object>() <= 1)
                {
                    continue;
                }
                var league = new League
                {
                    Id        = (int)item["league"]["id"],
                    ImgUrl    = (string)item["league"]["image_url"],
                    Name      = (string)item["league"]["name"],
                    Slug      = (string)item["videogame"]["slug"],
                    Url       = (string)item["league"]["url"],
                    Videogame = new Videogame
                    {
                        Id   = (int)item["videogame"]["id"],
                        Name = (string)item["videogame"]["name"],
                        Slug = (string)item["videogame"]["slug"],
                    }
                };
                var opponentOne = new Team
                {
                    Id      = (int)item["opponents"][0]["opponent"]["id"],
                    Acronym = (string)item["opponents"][0]["opponent"]["acronym"],
                    Name    = (string)item["opponents"][0]["opponent"]["name"],
                    ImgUrl  = (string)item["opponents"][0]["opponent"]["image_url"]
                };
                var opponentTwo = new Team
                {
                    Id      = (int)item["opponents"][1]["opponent"]["id"],
                    Acronym = (string)item["opponents"][1]["opponent"]["acronym"],
                    Name    = (string)item["opponents"][1]["opponent"]["name"],
                    ImgUrl  = (string)item["opponents"][1]["opponent"]["image_url"]
                };
                var series = new Series
                {
                    Id          = (int)item["serie"]["id"],
                    Name        = (string)item["serie"]["name"],
                    Prizepool   = (string)item["serie"]["prizepool"],
                    Season      = (string)item["serie"]["season"],
                    Year        = (int)item["serie"]["year"],
                    Description = (string)item["serie"]["description"],
                    FullName    = (string)item["serie"]["full_name"],
                    Tier        = (string)item["serie"]["tier"],
                    BeginDate   = ((DateTime)item["serie"]["begin_at"]).ToLocalTime(),
                };
                var upcomingGame = new UpcomingMatch
                {
                    ID            = (int)item["id"],
                    StartDate     = (string)item["begin_at"],
                    Draw          = (bool)item["draw"],
                    MatchType     = (string)item["match_type"],
                    Name          = (string)item["name"],
                    NumberOfGames = (int)item["number_of_games"],
                    Tournament    = (string)item["tournament"]["name"],
                    League        = league,
                    OpponentOne   = opponentOne,
                    OpponentTwo   = opponentTwo,
                    Series        = series
                };
                upcomingGames.Add(upcomingGame);
            }
            return(upcomingGames);
        }