Exemple #1
0
        public async Task <IActionResult> UpdateMatch([Bind("IdTournament, RoundNumber, IdPlayer1, IdPlayer2, Parties")]
                                                      Match match)
        {
            var Parties    = match.Parties;
            var retourApis = new List <RetourAPI>();

            foreach (var p in Parties)
            {
                p.IdTournament = match.IdTournament;
                p.RoundNumber  = match.RoundNumber;
                p.IdPlayer1    = match.IdPlayer1;
                p.IdPlayer2    = match.IdPlayer2;
                if (p.ResultPart != null)
                {
                    retourApis.Add(await CallAPI.CreateOrUpdatePartie(p));
                }
            }

            if (retourApis.Count > 0 && retourApis.All(r => r.Succes))
            {
                return(RedirectToAction("Tournoi", new { id = match.IdTournament }));
            }

            match = await CallAPI.GetMatch(match.IdTournament, match.RoundNumber, match.IdPlayer1);

            if (match.IdTournament == 0)
            {
                return(NotFound());
            }

            match.Parties = Parties;

            var decksP1 = await CallAPI.GetDeckOfPlayer(match.IdTournament, match.IdPlayer1);

            ViewData["DecksP1"] = decksP1.Append(new ViewDeck());
            var decksP2 = await CallAPI.GetDeckOfPlayer(match.IdTournament, match.IdPlayer2);

            ViewData["DecksP2"] = decksP2.Append(new ViewDeck());

            var empyParties = new List <ViewPartie>
            {
                new ViewPartie(), new ViewPartie(), new ViewPartie(), new ViewPartie(), new ViewPartie(),
                new ViewPartie(), new ViewPartie(), new ViewPartie(), new ViewPartie(), new ViewPartie()
            };

            if (match.Parties == null)
            {
                match.Parties = empyParties;
            }

            match.Parties     = match.Parties.Concat(empyParties).Take((match.Tournament.DeckListNumber * 2) - 1).ToList();
            ViewData["Title"] = "Match";
            return(View("~/Views/Admin/Match.cshtml", match));
        }