public ActionResult <ClubWithPlayerVM> Post(ClubWithPlayerVM clubWithPlayerVM) { var club = new Club() { Name = clubWithPlayerVM.Name }; _context.Clubs.Add(club); _context.SaveChanges(); foreach (var id in clubWithPlayerVM.PlayersIds) { var playerClub = new PlayerClub() { PlayerId = id, ClubId = club.Id }; _context.PlayerClubs.Add(playerClub); _context.SaveChanges(); } return(Ok(club)); }
public ActionResult <PlayerWithClubVM> Post(PlayerWithClubVM playerWithClub) { var player = new Player() { Name = playerWithClub.Name }; _context.Players.Add(player); _context.SaveChanges(); foreach (var id in playerWithClub.ClubsIds) { var playerClub = new PlayerClub() { PlayerId = player.Id, ClubId = id }; _context.PlayerClubs.Add(playerClub); _context.SaveChanges(); } return(Ok(player)); }