Esempio n. 1
0
        public async Task <ActionResult <Tournament> > Post(Tournament tournament)
        {
            _db.Tournaments.Add(tournament);
            await _db.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetTournament), new { id = tournament.TournamentId }, tournament));
        }
        public async Task <ActionResult <Match> > Post(Match match)
        {
            var thisTournament = await _db.Tournaments
                                 .FirstOrDefaultAsync(entry => entry.TournamentId == match.TournamentId);

            if (thisTournament != null)
            {
                System.Console.WriteLine(thisTournament.ToString());
                thisTournament.Matches.Add(match);
                _db.Tournaments.Update(thisTournament);
                await _db.SaveChangesAsync();
            }
            else
            {
                return(BadRequest());
            }
            // if(users != null)
            // {
            //   foreach(User user in users)
            //   {
            //     _db.MatchUsers.Add(new MatchUser(){ MatchId = match.MatchId, UserId = user.UserId});
            //     await _db.SaveChangesAsync();
            //   }
            // }
            return(CreatedAtAction(nameof(GetMatch), new { id = match.MatchId }, match));
        }