Beispiel #1
0
        public void TestAddWin()
        {
            Team team1 = new Team();

            team1.teamname = "testteam";
            int  gamemode = 1;
            Rank rank     = new Rank(team1, gamemode);

            Assert.AreEqual(rank.wins, 0);
            rank.AddWin();
            Assert.AreEqual(rank.wins, 1);
        }
        public IActionResult Put(Models.ChallengeUpdateModel model)
        {
            Challenge chal = _ChallengeRepository.GetChallengeById(model.challengeid);

            if (chal == null)
            {
                return(BadRequest("Challege does not exist."));
            }

            //compare teamnames
            bool success = chal.MakeReport(model.teamname, model.report);

            if (!success)
            {
                return(BadRequest("The team is not a part of this challenge."));
            }

            bool update = _ChallengeRepository.UpdateChallenge(chal);

            if (!update)
            {
                return(StatusCode(500));
            }
            //TODO if both reports are submitted, update ranks
            if (chal.Team1Report == null || chal.Team2Report == null)
            {
                return(Ok(new { message = "Result submitted. Waiting for other team." }));
            }

            bool?isDecided = chal.Victor();

            if (isDecided == null)
            {
                return(Ok(new { message = "Result submitted. Results don't match. No victor determined." }));
            }

            if ((bool)isDecided)
            {
                List <Rank> ranks = _RankRepository.GetRanksByTeam(chal.Team1.teamname);
                Rank        rank1 = null;
                foreach (var r in ranks)
                {
                    if (r.gamemodeid == chal.GameModeId)
                    {
                        rank1 = r;
                    }
                }
                rank1.AddWin();
                rank1.ranking = (int)rank1.CalculateRank();
                ranks         = _RankRepository.GetRanksByTeam(chal.Team2.teamname);
                Rank rank2 = null;
                foreach (var r in ranks)
                {
                    if (r.gamemodeid == chal.GameModeId)
                    {
                        rank2 = r;
                    }
                }
                rank2.AddLoss();
                rank2.ranking = (int)rank2.CalculateRank();

                _RankRepository.UpdateRank(rank1);
                _RankRepository.UpdateRank(rank2);

                return(Ok());
            }
            else
            {
                List <Rank> ranks = _RankRepository.GetRanksByTeam(chal.Team1.teamname);
                Rank        rank1 = null;
                foreach (var r in ranks)
                {
                    if (r.gamemodeid == chal.GameModeId)
                    {
                        rank1 = r;
                    }
                }
                rank1.AddLoss();
                rank1.ranking = (int)rank1.CalculateRank();

                ranks = _RankRepository.GetRanksByTeam(chal.Team2.teamname);
                Rank rank2 = null;
                foreach (var r in ranks)
                {
                    if (r.gamemodeid == chal.GameModeId)
                    {
                        rank2 = r;
                    }
                }
                rank2.AddWin();
                rank2.ranking = (int)rank1.CalculateRank();

                _RankRepository.UpdateRank(rank1);
                _RankRepository.UpdateRank(rank2);

                return(Ok());
            }
        }