<file_sep>﻿using System;
using System.Collections.Generic;

namespace EsportEvent.Domain
{
    public class Match
    {

        public Match()
        {
            Teams = new List<Team>();
        }

        public int Id { get; set; }

        public Game Game { get; set; }
        public string GameName { get; set; }

        public int TournamentId { get; set; }
        public DateTime GameDay { get; set; }
        public List<PlayerStats> PlayerStats { get; set; }
        public List<Team> Teams { get; set; }

    }
}<file_sep>﻿using Microsoft.EntityFrameworkCore.Migrations;
using System;
using System.Collections.Generic;

namespace EsportEvent.Data.Migrations
{
    public partial class SomeMinorChanges : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_Matches_Team_Team1Name_Team1GameName",
                table: "Matches");

            migrationBuilder.DropForeignKey(
                name: "FK_Matches_Team_Team2Name_Team2GameName",
                table: "Matches");

            migrationBuilder.DropForeignKey(
                name: "FK_Matches_Tournament_TournamentName_TournamentGameName",
                table: "Matches");

            migrationBuilder.DropForeignKey(
                name: "FK_Matches_Team_WinnerName_WinnerGameName",
                table: "Matches");

            migrationBuilder.DropForeignKey(
                name: "FK_PlayerGames_Team_TeamName_TeamGameName",
                table: "PlayerGames");

            migrationBuilder.DropForeignKey(
                name: "FK_Team_Tournament_TournamentName_TournamentGameName",
                table: "Team");

            migrationBuilder.DropPrimaryKey(
                name: "PK_Tournament",
                table: "Tournament");

            migrationBuilder.DropPrimaryKey(
                name: "PK_Team",
                table: "Team");

            migrationBuilder.DropIndex(
                name: "IX_Team_TournamentName_TournamentGameName",
                table: "Team");

            migrationBuilder.DropIndex(
                name: "IX_PlayerStats_MatchId",
                table: "PlayerStats");

            migrationBuilder.DropIndex(
                name: "IX_PlayerGames_TeamName_TeamGameName",
                table: "PlayerGames");

            migrationBuilder.DropIndex(
                name: "IX_Matches_Team1Name_Team1GameName",
                table: "Matches");

            migrationBuilder.DropIndex(
                name: "IX_Matches_Team2Name_Team2GameName",
                table: "Matches");

            migrationBuilder.DropIndex(
                name: "IX_Matches_TournamentName_TournamentGameName",
                table: "Matches");

            migrationBuilder.DropIndex(
                name: "IX_Matches_WinnerName_WinnerGameName",
                table: "Matches");

            migrationBuilder.DropColumn(
                name: "GameName",
                table: "Tournament");

            migrationBuilder.DropColumn(
                name: "GameName",
                table: "Team");

            migrationBuilder.DropColumn(
                name: "TournamentGameName",
                table: "Team");

            migrationBuilder.DropColumn(
                name: "TeamGameName",
                table: "PlayerGames");

            migrationBuilder.DropColumn(
                name: "Team1GameName",
                table: "Matches");

            migrationBuilder.DropColumn(
                name: "Team2GameName",
                table: "Matches");

            migrationBuilder.DropColumn(
                name: "TournamentGameName",
                table: "Matches");

            migrationBuilder.DropColumn(
                name: "WinnerGameName",
                table: "Matches");

            migrationBuilder.AddColumn<int>(
                name: "GameId",
                table: "Tournament",
                nullable: false,
                defaultValue: 0);

            migrationBuilder.AddColumn<int>(
                name: "GameId",
                table: "Team",
                nullable: false,
                defaultValue: 0);

            migrationBuilder.AddColumn<int>(
                name: "TournamentGameId",
                table: "Team",
                nullable: true);

            migrationBuilder.AddColumn<int>(
                name: "TeamGameId",
                table: "PlayerGames",
                nullable: true);

            migrationBuilder.AddColumn<int>(
                name: "Team1GameId",
                table: "Matches",
                nullable: true);

            migrationBuilder.AddColumn<int>(
                name: "Team1Id",
                table: "Matches",
                nullable: false,
                defaultValue: 0);

            migrationBuilder.AddColumn<int>(
                name: "Team2GameId",
                table: "Matches",
                nullable: true);

            migrationBuilder.AddColumn<int>(
                name: "Team2Id",
                table: "Matches",
                nullable: false,
                defaultValue: 0);

            migrationBuilder.AddColumn<int>(
                name: "TournamentGameId",
                table: "Matches",
                nullable: true);

            migrationBuilder.AddColumn<int>(
                name: "WinnerGameId",
                table: "Matches",
                nullable: true);

            migrationBuilder.AddColumn<int>(
                name: "WinnerId",
                table: "Matches",
                nullable: false,
                defaultValue: 0);

            migrationBuilder.AddPrimaryKey(
                name: "PK_Tournament",
                table: "Tournament",
                columns: new[] { "GameId", "Name" });

            migrationBuilder.AddPrimaryKey(
                name: "PK_Team",
                table: "Team",
                columns: new[] { "GameId", "Name" });

            migrationBuilder.CreateIndex(
                name: "IX_Tournament_Name",
                table: "Tournament",
                column: "Name");

            migrationBuilder.CreateIndex(
                name: "IX_Team_Name",
                table: "Team",
                column: "Name");

            migrationBuilder.CreateIndex(
                name: "IX_Team_TournamentGameId_TournamentName",
                table: "Team",
                columns: new[] { "TournamentGameId", "TournamentName" });

            migrationBuilder.CreateIndex(
                name: "IX_PlayerStats_PlayerGameId",
                table: "PlayerStats",
                column: "PlayerGameId");

            migrationBuilder.CreateIndex(
                name: "IX_PlayerGames_TeamGameId_TeamName",
                table: "PlayerGames",
                columns: new[] { "TeamGameId", "TeamName" });

            migrationBuilder.CreateIndex(
                name: "IX_Matches_Team1GameId_Team1Name",
                table: "Matches",
                columns: new[] { "Team1GameId", "Team1Name" });

            migrationBuilder.CreateIndex(
                name: "IX_Matches_Team2GameId_Team2Name",
                table: "Matches",
                columns: new[] { "Team2GameId", "Team2Name" });

            migrationBuilder.CreateIndex(
                name: "IX_Matches_TournamentGameId_TournamentName",
                table: "Matches",
                columns: new[] { "TournamentGameId", "TournamentName" });

            migrationBuilder.CreateIndex(
                name: "IX_Matches_WinnerGameId_WinnerName",
                table: "Matches",
                columns: new[] { "WinnerGameId", "WinnerName" });

            migrationBuilder.AddForeignKey(
                name: "FK_Matches_Team_Team1GameId_Team1Name",
                table: "Matches",
                columns: new[] { "Team1GameId", "Team1Name" },
                principalTable: "Team",
                principalColumns: new[] { "GameId", "Name" },
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_Matches_Team_Team2GameId_Team2Name",
                table: "Matches",
                columns: new[] { "Team2GameId", "Team2Name" },
                principalTable: "Team",
                principalColumns: new[] { "GameId", "Name" },
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_Matches_Tournament_TournamentGameId_TournamentName",
                table: "Matches",
                columns: new[] { "TournamentGameId", "TournamentName" },
                principalTable: "Tournament",
                principalColumns: new[] { "GameId", "Name" },
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_Matches_Team_WinnerGameId_WinnerName",
                table: "Matches",
                columns: new[] { "WinnerGameId", "WinnerName" },
                principalTable: "Team",
                principalColumns: new[] { "GameId", "Name" },
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_PlayerGames_Team_TeamGameId_TeamName",
                table: "PlayerGames",
                columns: new[] { "TeamGameId", "TeamName" },
                principalTable: "Team",
                principalColumns: new[] { "GameId", "Name" },
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_PlayerStats_PlayerGames_PlayerGameId",
                table: "PlayerStats",
                column: "PlayerGameId",
                principalTable: "PlayerGames",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_Team_Games_Name",
                table: "Team",
                column: "Name",
                principalTable: "Games",
                principalColumn: "Name",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_Team_Tournament_TournamentGameId_TournamentName",
                table: "Team",
                columns: new[] { "TournamentGameId", "TournamentName" },
                principalTable: "Tournament",
                principalColumns: new[] { "GameId", "Name" },
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_Tournament_Games_Name",
                table: "Tournament",
                column: "Name",
                principalTable: "Games",
                principalColumn: "Name",
                onDelete: ReferentialAction.Cascade);
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_Matches_Team_Team1GameId_Team1Name",
                table: "Matches");

            migrationBuilder.DropForeignKey(
                name: "FK_Matches_Team_Team2GameId_Team2Name",
                table: "Matches");

            migrationBuilder.DropForeignKey(
                name: "FK_Matches_Tournament_TournamentGameId_TournamentName",
                table: "Matches");

            migrationBuilder.DropForeignKey(
                name: "FK_Matches_Team_WinnerGameId_WinnerName",
                table: "Matches");

            migrationBuilder.DropForeignKey(
                name: "FK_PlayerGames_Team_TeamGameId_TeamName",
                table: "PlayerGames");

            migrationBuilder.DropForeignKey(
                name: "FK_PlayerStats_PlayerGames_PlayerGameId",
                table: "PlayerStats");

            migrationBuilder.DropForeignKey(
                name: "FK_Team_Games_Name",
                table: "Team");

            migrationBuilder.DropForeignKey(
                name: "FK_Team_Tournament_TournamentGameId_TournamentName",
                table: "Team");

            migrationBuilder.DropForeignKey(
                name: "FK_Tournament_Games_Name",
                table: "Tournament");

            migrationBuilder.DropPrimaryKey(
                name: "PK_Tournament",
                table: "Tournament");

            migrationBuilder.DropIndex(
                name: "IX_Tournament_Name",
                table: "Tournament");

            migrationBuilder.DropPrimaryKey(
                name: "PK_Team",
                table: "Team");

            migrationBuilder.DropIndex(
                name: "IX_Team_Name",
                table: "Team");

            migrationBuilder.DropIndex(
                name: "IX_Team_TournamentGameId_TournamentName",
                table: "Team");

            migrationBuilder.DropIndex(
                name: "IX_PlayerStats_PlayerGameId",
                table: "PlayerStats");

            migrationBuilder.DropIndex(
                name: "IX_PlayerGames_TeamGameId_TeamName",
                table: "PlayerGames");

            migrationBuilder.DropIndex(
                name: "IX_Matches_Team1GameId_Team1Name",
                table: "Matches");

            migrationBuilder.DropIndex(
                name: "IX_Matches_Team2GameId_Team2Name",
                table: "Matches");

            migrationBuilder.DropIndex(
                name: "IX_Matches_TournamentGameId_TournamentName",
                table: "Matches");

            migrationBuilder.DropIndex(
                name: "IX_Matches_WinnerGameId_WinnerName",
                table: "Matches");

            migrationBuilder.DropColumn(
                name: "GameId",
                table: "Tournament");

            migrationBuilder.DropColumn(
                name: "GameId",
                table: "Team");

            migrationBuilder.DropColumn(
                name: "TournamentGameId",
                table: "Team");

            migrationBuilder.DropColumn(
                name: "TeamGameId",
                table: "PlayerGames");

            migrationBuilder.DropColumn(
                name: "Team1GameId",
                table: "Matches");

            migrationBuilder.DropColumn(
                name: "Team1Id",
                table: "Matches");

            migrationBuilder.DropColumn(
                name: "Team2GameId",
                table: "Matches");

            migrationBuilder.DropColumn(
                name: "Team2Id",
                table: "Matches");

            migrationBuilder.DropColumn(
                name: "TournamentGameId",
                table: "Matches");

            migrationBuilder.DropColumn(
                name: "WinnerGameId",
                table: "Matches");

            migrationBuilder.DropColumn(
                name: "WinnerId",
                table: "Matches");

            migrationBuilder.AddColumn<string>(
                name: "GameName",
                table: "Tournament",
                nullable: false,
                defaultValue: "");

            migrationBuilder.AddColumn<string>(
                name: "GameName",
                table: "Team",
                nullable: false,
                defaultValue: "");

            migrationBuilder.AddColumn<string>(
                name: "TournamentGameName",
                table: "Team",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "TeamGameName",
                table: "PlayerGames",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "Team1GameName",
                table: "Matches",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "Team2GameName",
                table: "Matches",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "TournamentGameName",
                table: "Matches",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "WinnerGameName",
                table: "Matches",
                nullable: true);

            migrationBuilder.AddPrimaryKey(
                name: "PK_Tournament",
                table: "Tournament",
                columns: new[] { "Name", "GameName" });

            migrationBuilder.AddPrimaryKey(
                name: "PK_Team",
                table: "Team",
                columns: new[] { "Name", "GameName" });

            migrationBuilder.CreateIndex(
                name: "IX_Team_TournamentName_TournamentGameName",
                table: "Team",
                columns: new[] { "TournamentName", "TournamentGameName" });

            migrationBuilder.CreateIndex(
                name: "IX_PlayerStats_MatchId",
                table: "PlayerStats",
                column: "MatchId",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_PlayerGames_TeamName_TeamGameName",
                table: "PlayerGames",
                columns: new[] { "TeamName", "TeamGameName" });

            migrationBuilder.CreateIndex(
                name: "IX_Matches_Team1Name_Team1GameName",
                table: "Matches",
                columns: new[] { "Team1Name", "Team1GameName" });

            migrationBuilder.CreateIndex(
                name: "IX_Matches_Team2Name_Team2GameName",
                table: "Matches",
                columns: new[] { "Team2Name", "Team2GameName" });

            migrationBuilder.CreateIndex(
                name: "IX_Matches_TournamentName_TournamentGameName",
                table: "Matches",
                columns: new[] { "TournamentName", "TournamentGameName" });

            migrationBuilder.CreateIndex(
                name: "IX_Matches_WinnerName_WinnerGameName",
                table: "Matches",
                columns: new[] { "WinnerName", "WinnerGameName" });

            migrationBuilder.AddForeignKey(
                name: "FK_Matches_Team_Team1Name_Team1GameName",
                table: "Matches",
                columns: new[] { "Team1Name", "Team1GameName" },
                principalTable: "Team",
                principalColumns: new[] { "Name", "GameName" },
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_Matches_Team_Team2Name_Team2GameName",
                table: "Matches",
                columns: new[] { "Team2Name", "Team2GameName" },
                principalTable: "Team",
                principalColumns: new[] { "Name", "GameName" },
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_Matches_Tournament_TournamentName_TournamentGameName",
                table: "Matches",
                columns: new[] { "TournamentName", "TournamentGameName" },
                principalTable: "Tournament",
                principalColumns: new[] { "Name", "GameName" },
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_Matches_Team_WinnerName_WinnerGameName",
                table: "Matches",
                columns: new[] { "WinnerName", "WinnerGameName" },
                principalTable: "Team",
                principalColumns: new[] { "Name", "GameName" },
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_PlayerGames_Team_TeamName_TeamGameName",
                table: "PlayerGames",
                columns: new[] { "TeamName", "TeamGameName" },
                principalTable: "Team",
                principalColumns: new[] { "Name", "GameName" },
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_Team_Tournament_TournamentName_TournamentGameName",
                table: "Team",
                columns: new[] { "TournamentName", "TournamentGameName" },
                principalTable: "Tournament",
                principalColumns: new[] { "Name", "GameName" },
                onDelete: ReferentialAction.Restrict);
        }
    }
}
<file_sep>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EsportEvent.Domain
{
    public class PlayerGame
    {
        public PlayerGame()
        {

        }

        public int Id { get; set; }

        public string PlayerUserName { get; set; }
        public Player Player { get; set; }

        public string GameName { get; set; }
        public Game Game { get; set; }
   
        public int TeamId { get; set; }
        public Team Team {get; set;}

        public string PlayerNickName { get; set; }
        public string PlayerRole { get; set; }
    }
}
<file_sep>﻿using Microsoft.EntityFrameworkCore.Migrations;
using System;
using System.Collections.Generic;

namespace EsportEvent.Data.Migrations
{
    public partial class minorChangses : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_PlayerGames_Players_PlayerUserName",
                table: "PlayerGames");

            migrationBuilder.DropIndex(
                name: "IX_PlayerGames_PlayerUserName",
                table: "PlayerGames");

            migrationBuilder.DropColumn(
                name: "PlayerUserName",
                table: "PlayerGames");

            migrationBuilder.AlterColumn<string>(
                name: "PlayerId",
                table: "PlayerGames",
                nullable: true,
                oldClrType: typeof(int));

            migrationBuilder.AddColumn<string>(
                name: "GameName",
                table: "Matches",
                nullable: true);

            migrationBuilder.CreateIndex(
                name: "IX_PlayerGames_PlayerId",
                table: "PlayerGames",
                column: "PlayerId");

            migrationBuilder.CreateIndex(
                name: "IX_Matches_GameName",
                table: "Matches",
                column: "GameName");

            migrationBuilder.AddForeignKey(
                name: "FK_Matches_Games_GameName",
                table: "Matches",
                column: "GameName",
                principalTable: "Games",
                principalColumn: "Name",
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_PlayerGames_Players_PlayerId",
                table: "PlayerGames",
                column: "PlayerId",
                principalTable: "Players",
                principalColumn: "UserName",
                onDelete: ReferentialAction.Restrict);
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_Matches_Games_GameName",
                table: "Matches");

            migrationBuilder.DropForeignKey(
                name: "FK_PlayerGames_Players_PlayerId",
                table: "PlayerGames");

            migrationBuilder.DropIndex(
                name: "IX_PlayerGames_PlayerId",
                table: "PlayerGames");

            migrationBuilder.DropIndex(
                name: "IX_Matches_GameName",
                table: "Matches");

            migrationBuilder.DropColumn(
                name: "GameName",
                table: "Matches");

            migrationBuilder.AlterColumn<int>(
                name: "PlayerId",
                table: "PlayerGames",
                nullable: false,
                oldClrType: typeof(string),
                oldNullable: true);

            migrationBuilder.AddColumn<string>(
                name: "PlayerUserName",
                table: "PlayerGames",
                nullable: true);

            migrationBuilder.CreateIndex(
                name: "IX_PlayerGames_PlayerUserName",
                table: "PlayerGames",
                column: "PlayerUserName");

            migrationBuilder.AddForeignKey(
                name: "FK_PlayerGames_Players_PlayerUserName",
                table: "PlayerGames",
                column: "PlayerUserName",
                principalTable: "Players",
                principalColumn: "UserName",
                onDelete: ReferentialAction.Restrict);
        }
    }
}
<file_sep>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EsportEvent.Domain
{
   public class Player
    {
        public Player()
        {
            Games = new List<PlayerGame>();
        }
        public string UserName { get; set; }
        public string Name { get; set; }
        public List<PlayerGame> Games { get; set; }
        
    }
}
<file_sep>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EsportEvent.Domain
{
    public class Game
    {
        public Game()
        {
        }
        public string Name { get; set; }
        public string Publisher { get; set; }
        public DateTime ReleaseDate { get; set; }
        public int Tournaments { get; set; }
        
    }
}
<file_sep>﻿using Microsoft.EntityFrameworkCore.Migrations;
using System;
using System.Collections.Generic;

namespace EsportEvent.Data.Migrations
{
    public partial class AddedTeamMatchJoinTable : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "TeamMatch",
                columns: table => new
                {
                    MatchId = table.Column<int>(nullable: false),
                    TeamId = table.Column<int>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_TeamMatch", x => new { x.MatchId, x.TeamId });
                });
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "TeamMatch");
        }
    }
}
<file_sep>﻿using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using EsportEvent.Domain;
using Microsoft.Extensions.Logging.Console;
using System;

namespace EsportEvent.Data
{
    public class EsportEventContext : DbContext
    {
        public DbSet<Player> Players { get; set; }
        public DbSet<Game> Games { get; set; }
        public DbSet<PlayerGame> PlayerGames { get; set; }
        public DbSet<Match> Matches { get; set; }
        public DbSet<PlayerStats> PlayerStats { get; set; }
        public DbSet<Team> Team { get; set; }
        public DbSet<Tournament> Tournament { get; set; }
        public DbSet<TeamMatch> TeamMatch { get; set; }



        public static readonly LoggerFactory EsportloggerFactory
                = new LoggerFactory(new[]{
           new ConsoleLoggerProvider((category, level) => category == DbLoggerCategory.Database.Command.Name && level == LogLevel.Information, true)
                });

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Team>().HasKey(m => new {m.Id });
            modelBuilder.Entity<Game>().HasKey(m => new { m.Name });
            modelBuilder.Entity<Player>().HasKey(p => new { p.UserName });
            modelBuilder.Entity<TeamMatch>().HasKey(tm => new {tm.MatchId, tm.TeamId });
        }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            //Egentligen inte önskligt att ha connectionstring hårdkodad på detta sätt.
            optionsBuilder
                .EnableSensitiveDataLogging()
                //.UseLoggerFactory(EsportloggerFactory)
                .UseSqlServer("Server = (localdb)\\mssqllocaldb; Database = EsportTournament; Trusted_connection = True;");

        }

    }
}
<file_sep>﻿using Microsoft.EntityFrameworkCore.Migrations;
using System;
using System.Collections.Generic;

namespace EsportEvent.Data.Migrations
{
    public partial class AddedDbset : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_Match_Team_Team1Name_Team1GameName",
                table: "Match");

            migrationBuilder.DropForeignKey(
                name: "FK_Match_Team_Team2Name_Team2GameName",
                table: "Match");

            migrationBuilder.DropForeignKey(
                name: "FK_Match_Tournament_TournamentName_TournamentGameName",
                table: "Match");

            migrationBuilder.DropForeignKey(
                name: "FK_Match_Team_WinnerName_WinnerGameName",
                table: "Match");

            migrationBuilder.DropForeignKey(
                name: "FK_PlayerStats_Match_MatchId",
                table: "PlayerStats");

            migrationBuilder.DropPrimaryKey(
                name: "PK_Match",
                table: "Match");

            migrationBuilder.RenameTable(
                name: "Match",
                newName: "Matches");

            migrationBuilder.RenameIndex(
                name: "IX_Match_WinnerName_WinnerGameName",
                table: "Matches",
                newName: "IX_Matches_WinnerName_WinnerGameName");

            migrationBuilder.RenameIndex(
                name: "IX_Match_TournamentName_TournamentGameName",
                table: "Matches",
                newName: "IX_Matches_TournamentName_TournamentGameName");

            migrationBuilder.RenameIndex(
                name: "IX_Match_Team2Name_Team2GameName",
                table: "Matches",
                newName: "IX_Matches_Team2Name_Team2GameName");

            migrationBuilder.RenameIndex(
                name: "IX_Match_Team1Name_Team1GameName",
                table: "Matches",
                newName: "IX_Matches_Team1Name_Team1GameName");

            migrationBuilder.AddPrimaryKey(
                name: "PK_Matches",
                table: "Matches",
                column: "Id");

            migrationBuilder.AddForeignKey(
                name: "FK_Matches_Team_Team1Name_Team1GameName",
                table: "Matches",
                columns: new[] { "Team1Name", "Team1GameName" },
                principalTable: "Team",
                principalColumns: new[] { "Name", "GameName" },
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_Matches_Team_Team2Name_Team2GameName",
                table: "Matches",
                columns: new[] { "Team2Name", "Team2GameName" },
                principalTable: "Team",
                principalColumns: new[] { "Name", "GameName" },
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_Matches_Tournament_TournamentName_TournamentGameName",
                table: "Matches",
                columns: new[] { "TournamentName", "TournamentGameName" },
                principalTable: "Tournament",
                principalColumns: new[] { "Name", "GameName" },
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_Matches_Team_WinnerName_WinnerGameName",
                table: "Matches",
                columns: new[] { "WinnerName", "WinnerGameName" },
                principalTable: "Team",
                principalColumns: new[] { "Name", "GameName" },
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_PlayerStats_Matches_MatchId",
                table: "PlayerStats",
                column: "MatchId",
                principalTable: "Matches",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_Matches_Team_Team1Name_Team1GameName",
                table: "Matches");

            migrationBuilder.DropForeignKey(
                name: "FK_Matches_Team_Team2Name_Team2GameName",
                table: "Matches");

            migrationBuilder.DropForeignKey(
                name: "FK_Matches_Tournament_TournamentName_TournamentGameName",
                table: "Matches");

            migrationBuilder.DropForeignKey(
                name: "FK_Matches_Team_WinnerName_WinnerGameName",
                table: "Matches");

            migrationBuilder.DropForeignKey(
                name: "FK_PlayerStats_Matches_MatchId",
                table: "PlayerStats");

            migrationBuilder.DropPrimaryKey(
                name: "PK_Matches",
                table: "Matches");

            migrationBuilder.RenameTable(
                name: "Matches",
                newName: "Match");

            migrationBuilder.RenameIndex(
                name: "IX_Matches_WinnerName_WinnerGameName",
                table: "Match",
                newName: "IX_Match_WinnerName_WinnerGameName");

            migrationBuilder.RenameIndex(
                name: "IX_Matches_TournamentName_TournamentGameName",
                table: "Match",
                newName: "IX_Match_TournamentName_TournamentGameName");

            migrationBuilder.RenameIndex(
                name: "IX_Matches_Team2Name_Team2GameName",
                table: "Match",
                newName: "IX_Match_Team2Name_Team2GameName");

            migrationBuilder.RenameIndex(
                name: "IX_Matches_Team1Name_Team1GameName",
                table: "Match",
                newName: "IX_Match_Team1Name_Team1GameName");

            migrationBuilder.AddPrimaryKey(
                name: "PK_Match",
                table: "Match",
                column: "Id");

            migrationBuilder.AddForeignKey(
                name: "FK_Match_Team_Team1Name_Team1GameName",
                table: "Match",
                columns: new[] { "Team1Name", "Team1GameName" },
                principalTable: "Team",
                principalColumns: new[] { "Name", "GameName" },
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_Match_Team_Team2Name_Team2GameName",
                table: "Match",
                columns: new[] { "Team2Name", "Team2GameName" },
                principalTable: "Team",
                principalColumns: new[] { "Name", "GameName" },
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_Match_Tournament_TournamentName_TournamentGameName",
                table: "Match",
                columns: new[] { "TournamentName", "TournamentGameName" },
                principalTable: "Tournament",
                principalColumns: new[] { "Name", "GameName" },
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_Match_Team_WinnerName_WinnerGameName",
                table: "Match",
                columns: new[] { "WinnerName", "WinnerGameName" },
                principalTable: "Team",
                principalColumns: new[] { "Name", "GameName" },
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_PlayerStats_Match_MatchId",
                table: "PlayerStats",
                column: "MatchId",
                principalTable: "Match",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }
    }
}
<file_sep>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using EsportEvent.Data;
using EsportEvent.Domain;

namespace Testdb
{
    class Program
    {
        static void Main(string[] args)
        {
            var gameRepo = new GameRepo();
            var matchRepo = new MatchRepo();
                var playerGameRepo = new PlayerGameRepo();
            var playerRepo = new PlayerRepo();
                var playerStats = new PlayerStatsRepo();
            var teamRepo = new TeamRepo();
            var teamMatchReop = new TeamMatchRepo();
            var TournamentRepo = new TournamentRepo();
           

        }
    }
}
           
<file_sep>﻿using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using System;
using System.Collections.Generic;

namespace EsportEvent.Data.Migrations
{
    public partial class initfullTableDiagram : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_Games_Players_PlayerId",
                table: "Games");

            migrationBuilder.DropForeignKey(
                name: "FK_PlayerGames_Players_PlayerId",
                table: "PlayerGames");

            migrationBuilder.DropPrimaryKey(
                name: "PK_Players",
                table: "Players");

            migrationBuilder.DropPrimaryKey(
                name: "PK_PlayerGames",
                table: "PlayerGames");

            migrationBuilder.DropIndex(
                name: "IX_Games_PlayerId",
                table: "Games");

            migrationBuilder.DropColumn(
                name: "Id",
                table: "Players");

            migrationBuilder.DropColumn(
                name: "PlayerId",
                table: "Games");

            migrationBuilder.AddColumn<string>(
                name: "UserName",
                table: "Players",
                nullable: false,
                defaultValue: "");

            migrationBuilder.AddColumn<int>(
                name: "Id",
                table: "PlayerGames",
                nullable: false,
                defaultValue: 0)
                .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);

            migrationBuilder.AddColumn<string>(
                name: "PlayerUserName",
                table: "PlayerGames",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "TeamGameName",
                table: "PlayerGames",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "TeamName",
                table: "PlayerGames",
                nullable: true);

            migrationBuilder.AddPrimaryKey(
                name: "PK_Players",
                table: "Players",
                column: "UserName");

            migrationBuilder.AddPrimaryKey(
                name: "PK_PlayerGames",
                table: "PlayerGames",
                column: "Id");

            migrationBuilder.CreateTable(
                name: "Tournament",
                columns: table => new
                {
                    Name = table.Column<string>(nullable: false),
                    GameName = table.Column<string>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Tournament", x => new { x.Name, x.GameName });
                });

            migrationBuilder.CreateTable(
                name: "Team",
                columns: table => new
                {
                    Name = table.Column<string>(nullable: false),
                    GameName = table.Column<string>(nullable: false),
                    TournamentGameName = table.Column<string>(nullable: true),
                    TournamentName = table.Column<string>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Team", x => new { x.Name, x.GameName });
                    table.ForeignKey(
                        name: "FK_Team_Tournament_TournamentName_TournamentGameName",
                        columns: x => new { x.TournamentName, x.TournamentGameName },
                        principalTable: "Tournament",
                        principalColumns: new[] { "Name", "GameName" },
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "Match",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                    GamePlayed = table.Column<DateTime>(nullable: false),
                    Team1GameName = table.Column<string>(nullable: true),
                    Team1Name = table.Column<string>(nullable: true),
                    Team2GameName = table.Column<string>(nullable: true),
                    Team2Name = table.Column<string>(nullable: true),
                    TournamentGameName = table.Column<string>(nullable: true),
                    TournamentName = table.Column<string>(nullable: true),
                    WinnerGameName = table.Column<string>(nullable: true),
                    WinnerName = table.Column<string>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Match", x => x.Id);
                    table.ForeignKey(
                        name: "FK_Match_Team_Team1Name_Team1GameName",
                        columns: x => new { x.Team1Name, x.Team1GameName },
                        principalTable: "Team",
                        principalColumns: new[] { "Name", "GameName" },
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_Match_Team_Team2Name_Team2GameName",
                        columns: x => new { x.Team2Name, x.Team2GameName },
                        principalTable: "Team",
                        principalColumns: new[] { "Name", "GameName" },
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_Match_Tournament_TournamentName_TournamentGameName",
                        columns: x => new { x.TournamentName, x.TournamentGameName },
                        principalTable: "Tournament",
                        principalColumns: new[] { "Name", "GameName" },
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_Match_Team_WinnerName_WinnerGameName",
                        columns: x => new { x.WinnerName, x.WinnerGameName },
                        principalTable: "Team",
                        principalColumns: new[] { "Name", "GameName" },
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "PlayerStats",
                columns: table => new
                {
                    MatchId = table.Column<int>(nullable: false),
                    PlayerGameId = table.Column<int>(nullable: false),
                    Assists = table.Column<int>(nullable: false),
                    Deaths = table.Column<int>(nullable: false),
                    Kills = table.Column<int>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_PlayerStats", x => new { x.MatchId, x.PlayerGameId });
                    table.ForeignKey(
                        name: "FK_PlayerStats_Match_MatchId",
                        column: x => x.MatchId,
                        principalTable: "Match",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_PlayerGames_PlayerUserName",
                table: "PlayerGames",
                column: "PlayerUserName");

            migrationBuilder.CreateIndex(
                name: "IX_PlayerGames_TeamName_TeamGameName",
                table: "PlayerGames",
                columns: new[] { "TeamName", "TeamGameName" });

            migrationBuilder.CreateIndex(
                name: "IX_Match_Team1Name_Team1GameName",
                table: "Match",
                columns: new[] { "Team1Name", "Team1GameName" });

            migrationBuilder.CreateIndex(
                name: "IX_Match_Team2Name_Team2GameName",
                table: "Match",
                columns: new[] { "Team2Name", "Team2GameName" });

            migrationBuilder.CreateIndex(
                name: "IX_Match_TournamentName_TournamentGameName",
                table: "Match",
                columns: new[] { "TournamentName", "TournamentGameName" });

            migrationBuilder.CreateIndex(
                name: "IX_Match_WinnerName_WinnerGameName",
                table: "Match",
                columns: new[] { "WinnerName", "WinnerGameName" });

            migrationBuilder.CreateIndex(
                name: "IX_PlayerStats_MatchId",
                table: "PlayerStats",
                column: "MatchId",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_Team_TournamentName_TournamentGameName",
                table: "Team",
                columns: new[] { "TournamentName", "TournamentGameName" });

            migrationBuilder.AddForeignKey(
                name: "FK_PlayerGames_Players_PlayerUserName",
                table: "PlayerGames",
                column: "PlayerUserName",
                principalTable: "Players",
                principalColumn: "UserName",
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_PlayerGames_Team_TeamName_TeamGameName",
                table: "PlayerGames",
                columns: new[] { "TeamName", "TeamGameName" },
                principalTable: "Team",
                principalColumns: new[] { "Name", "GameName" },
                onDelete: ReferentialAction.Restrict);
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_PlayerGames_Players_PlayerUserName",
                table: "PlayerGames");

            migrationBuilder.DropForeignKey(
                name: "FK_PlayerGames_Team_TeamName_TeamGameName",
                table: "PlayerGames");

            migrationBuilder.DropTable(
                name: "PlayerStats");

            migrationBuilder.DropTable(
                name: "Match");

            migrationBuilder.DropTable(
                name: "Team");

            migrationBuilder.DropTable(
                name: "Tournament");

            migrationBuilder.DropPrimaryKey(
                name: "PK_Players",
                table: "Players");

            migrationBuilder.DropPrimaryKey(
                name: "PK_PlayerGames",
                table: "PlayerGames");

            migrationBuilder.DropIndex(
                name: "IX_PlayerGames_PlayerUserName",
                table: "PlayerGames");

            migrationBuilder.DropIndex(
                name: "IX_PlayerGames_TeamName_TeamGameName",
                table: "PlayerGames");

            migrationBuilder.DropColumn(
                name: "UserName",
                table: "Players");

            migrationBuilder.DropColumn(
                name: "Id",
                table: "PlayerGames");

            migrationBuilder.DropColumn(
                name: "PlayerUserName",
                table: "PlayerGames");

            migrationBuilder.DropColumn(
                name: "TeamGameName",
                table: "PlayerGames");

            migrationBuilder.DropColumn(
                name: "TeamName",
                table: "PlayerGames");

            migrationBuilder.AddColumn<int>(
                name: "Id",
                table: "Players",
                nullable: false,
                defaultValue: 0)
                .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);

            migrationBuilder.AddColumn<int>(
                name: "PlayerId",
                table: "Games",
                nullable: true);

            migrationBuilder.AddPrimaryKey(
                name: "PK_Players",
                table: "Players",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_PlayerGames",
                table: "PlayerGames",
                columns: new[] { "PlayerId", "GameId" });

            migrationBuilder.CreateIndex(
                name: "IX_Games_PlayerId",
                table: "Games",
                column: "PlayerId");

            migrationBuilder.AddForeignKey(
                name: "FK_Games_Players_PlayerId",
                table: "Games",
                column: "PlayerId",
                principalTable: "Players",
                principalColumn: "Id",
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_PlayerGames_Players_PlayerId",
                table: "PlayerGames",
                column: "PlayerId",
                principalTable: "Players",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }
    }
}
<file_sep>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using EsportEvent.Domain;
using Microsoft.EntityFrameworkCore;

namespace EsportEvent.Data
{
    public class PlayerGameRepo : GenericEsportRepo<PlayerGame, EsportEventContext>
    {
        public override void Add(PlayerGame playerGame)
        {
            PlayerRepo pr = new PlayerRepo();
            TeamRepo tr = new TeamRepo();
            GameRepo gr = new GameRepo();

            if (null != pr.FindBy(p => p.UserName == playerGame.Player.UserName).FirstOrDefault())
            {
                pr.Add(playerGame.Player);
                pr.Save();
            }

            if (null != tr.FindBy(p => p.Id == playerGame.Team.Id).FirstOrDefault())
            {
                tr.Add(playerGame.Team);
                tr.Save();
            }
            if (null != gr.FindBy(g => g.Name == playerGame.GameName).FirstOrDefault())
            {
                gr.Add(playerGame.Game);
                gr.Save();
            }
            
                Context.PlayerGames.Add(new PlayerGame
                {
                    GameName=playerGame.GameName,
                    PlayerNickName=playerGame.PlayerNickName,
                    PlayerRole=playerGame.PlayerRole,
                    PlayerUserName=playerGame.PlayerUserName,
                    Player=playerGame.Player,
                    
                });

            Save();
            
        }

        //Jag har valt att göra denna async då jag tror att admin till mintt program kommer att söka efter spelare många 
        //Gånger undet dens arbetsdag. Därför vill jag att detta ska kunna ske snabbt och att programmet kan jobba med annat
        //under tiden som den hämta detta från en extern databas. 
        public override async Task<ICollection<PlayerGame>> GetAllAsync()
        {
             return await Context.PlayerGames
                  .Include(g => g.Game)
                  .Include(t => t.Team)
                  .Include(p => p.Player)
                  .ThenInclude(p => p.Games).ToListAsync();
        }

        public override void Update(PlayerGame playerGame)
        {
            PlayerRepo pr = new PlayerRepo();
            TeamRepo tr = new TeamRepo();
            GameRepo gr = new GameRepo();

            if (null != pr.FindBy(p => p.UserName == playerGame.Player.UserName).FirstOrDefault())
            {
                pr.Add(playerGame.Player);
                pr.Save();
            }

            if (null != tr.FindBy(p => p.Id == playerGame.Team.Id).FirstOrDefault())
            {
                tr.Add(playerGame.Team);
                tr.Save();
            }
            if (null != gr.FindBy(g => g.Name == playerGame.GameName).FirstOrDefault())
            {
                gr.Add(playerGame.Game);
                gr.Save();
            }

            Context.PlayerGames.Update(playerGame);
            Save();
                
        }

    }
}
<file_sep>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EsportEvent.Domain
{
    public class PlayerStats
    {
        public PlayerStats()
        {

        }
        public int Id { get; set; }

        public int MatchId { get; set; }
        public Match Match { get; set; }

        public int PlayerGameId { get; set; }
        public PlayerGame PlayerGame { get; set; }

        public int Kills { get; set; }
        public int Deaths { get; set; }
        public int Assists { get; set; }

    }
}
<file_sep>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EsportEvent.Domain
{
    public class TeamMatch
    {
        public TeamMatch()
        {
        }

        public Team Team { get; set; }
        public int TeamId { get; set; }

        public Match Match { get; set; }
        public int MatchId { get; set; }

    }
}
<file_sep>﻿using EsportEvent.Domain;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EsportEvent.Data
{
    public class TeamMatchRepo : GenericEsportRepo<TeamMatch, EsportEventContext>
    {
    }
}
<file_sep>﻿using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using System;
using System.Collections.Generic;

namespace EsportEvent.Data.Migrations
{
    public partial class mc : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_Matches_Team_Team1GameName_Team1Name",
                table: "Matches");

            migrationBuilder.DropForeignKey(
                name: "FK_Matches_Team_Team2GameName_Team2Name",
                table: "Matches");

            migrationBuilder.DropForeignKey(
                name: "FK_Matches_Tournament_TournamentGameName_TournamentName",
                table: "Matches");

            migrationBuilder.DropForeignKey(
                name: "FK_Matches_Team_WinnerGameName_WinnerName",
                table: "Matches");

            migrationBuilder.DropForeignKey(
                name: "FK_PlayerGames_Players_PlayerId",
                table: "PlayerGames");

            migrationBuilder.DropForeignKey(
                name: "FK_PlayerGames_Team_TeamGameName_TeamName",
                table: "PlayerGames");

            migrationBuilder.DropForeignKey(
                name: "FK_Team_Games_GameName",
                table: "Team");

            migrationBuilder.DropForeignKey(
                name: "FK_Tournament_Games_GameName",
                table: "Tournament");

            migrationBuilder.DropPrimaryKey(
                name: "PK_Tournament",
                table: "Tournament");

            migrationBuilder.DropPrimaryKey(
                name: "PK_Team",
                table: "Team");

            migrationBuilder.DropPrimaryKey(
                name: "PK_PlayerStats",
                table: "PlayerStats");

            migrationBuilder.DropIndex(
                name: "IX_PlayerGames_PlayerId",
                table: "PlayerGames");

            migrationBuilder.DropIndex(
                name: "IX_PlayerGames_TeamGameName_TeamName",
                table: "PlayerGames");

            migrationBuilder.DropIndex(
                name: "IX_Matches_Team1GameName_Team1Name",
                table: "Matches");

            migrationBuilder.DropIndex(
                name: "IX_Matches_Team2GameName_Team2Name",
                table: "Matches");

            migrationBuilder.DropIndex(
                name: "IX_Matches_TournamentGameName_TournamentName",
                table: "Matches");

            migrationBuilder.DropIndex(
                name: "IX_Matches_WinnerGameName_WinnerName",
                table: "Matches");

            migrationBuilder.DropColumn(
                name: "PlayerId",
                table: "PlayerGames");

            migrationBuilder.DropColumn(
                name: "TeamGameName",
                table: "PlayerGames");

            migrationBuilder.DropColumn(
                name: "Team1GameName",
                table: "Matches");

            migrationBuilder.DropColumn(
                name: "Team1Id",
                table: "Matches");

            migrationBuilder.DropColumn(
                name: "Team1Name",
                table: "Matches");

            migrationBuilder.DropColumn(
                name: "Team2GameName",
                table: "Matches");

            migrationBuilder.DropColumn(
                name: "Team2Id",
                table: "Matches");

            migrationBuilder.DropColumn(
                name: "Team2Name",
                table: "Matches");

            migrationBuilder.DropColumn(
                name: "TournamentGameName",
                table: "Matches");

            migrationBuilder.DropColumn(
                name: "TournamentName",
                table: "Matches");

            migrationBuilder.DropColumn(
                name: "WinnerGameName",
                table: "Matches");

            migrationBuilder.DropColumn(
                name: "WinnerName",
                table: "Matches");

            migrationBuilder.RenameColumn(
                name: "TeamName",
                table: "PlayerGames",
                newName: "PlayerUserName");

            migrationBuilder.RenameColumn(
                name: "WinnerId",
                table: "Matches",
                newName: "TeamId");

            migrationBuilder.AlterColumn<string>(
                name: "Name",
                table: "Tournament",
                nullable: true,
                oldClrType: typeof(string));

            migrationBuilder.AlterColumn<string>(
                name: "GameName",
                table: "Tournament",
                nullable: true,
                oldClrType: typeof(string));

            migrationBuilder.AddColumn<int>(
                name: "Id",
                table: "Tournament",
                nullable: false,
                defaultValue: 0)
                .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);

            migrationBuilder.AlterColumn<string>(
                name: "Name",
                table: "Team",
                nullable: true,
                oldClrType: typeof(string));

            migrationBuilder.AlterColumn<string>(
                name: "GameName",
                table: "Team",
                nullable: true,
                oldClrType: typeof(string));

            migrationBuilder.AddColumn<int>(
                name: "Id",
                table: "Team",
                nullable: false,
                defaultValue: 0)
                .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);

            migrationBuilder.AddColumn<int>(
                name: "MatchId",
                table: "Team",
                nullable: true);

            migrationBuilder.AddColumn<int>(
                name: "Id",
                table: "PlayerStats",
                nullable: false,
                defaultValue: 0)
                .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);

            migrationBuilder.AddColumn<int>(
                name: "TeamId",
                table: "PlayerGames",
                nullable: false,
                defaultValue: 0);

            migrationBuilder.AddColumn<int>(
                name: "TournamentId",
                table: "Matches",
                nullable: true);

            migrationBuilder.AddPrimaryKey(
                name: "PK_Tournament",
                table: "Tournament",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_Team",
                table: "Team",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_PlayerStats",
                table: "PlayerStats",
                column: "Id");

            migrationBuilder.CreateIndex(
                name: "IX_Tournament_GameName",
                table: "Tournament",
                column: "GameName");

            migrationBuilder.CreateIndex(
                name: "IX_Team_GameName",
                table: "Team",
                column: "GameName");

            migrationBuilder.CreateIndex(
                name: "IX_Team_MatchId",
                table: "Team",
                column: "MatchId");

            migrationBuilder.CreateIndex(
                name: "IX_PlayerStats_MatchId",
                table: "PlayerStats",
                column: "MatchId");

            migrationBuilder.CreateIndex(
                name: "IX_PlayerGames_PlayerUserName",
                table: "PlayerGames",
                column: "PlayerUserName");

            migrationBuilder.CreateIndex(
                name: "IX_PlayerGames_TeamId",
                table: "PlayerGames",
                column: "TeamId");

            migrationBuilder.CreateIndex(
                name: "IX_Matches_TournamentId",
                table: "Matches",
                column: "TournamentId");

            migrationBuilder.AddForeignKey(
                name: "FK_Matches_Tournament_TournamentId",
                table: "Matches",
                column: "TournamentId",
                principalTable: "Tournament",
                principalColumn: "Id",
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_PlayerGames_Players_PlayerUserName",
                table: "PlayerGames",
                column: "PlayerUserName",
                principalTable: "Players",
                principalColumn: "UserName",
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_PlayerGames_Team_TeamId",
                table: "PlayerGames",
                column: "TeamId",
                principalTable: "Team",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_Team_Games_GameName",
                table: "Team",
                column: "GameName",
                principalTable: "Games",
                principalColumn: "Name",
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_Team_Matches_MatchId",
                table: "Team",
                column: "MatchId",
                principalTable: "Matches",
                principalColumn: "Id",
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_Tournament_Games_GameName",
                table: "Tournament",
                column: "GameName",
                principalTable: "Games",
                principalColumn: "Name",
                onDelete: ReferentialAction.Restrict);
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_Matches_Tournament_TournamentId",
                table: "Matches");

            migrationBuilder.DropForeignKey(
                name: "FK_PlayerGames_Players_PlayerUserName",
                table: "PlayerGames");

            migrationBuilder.DropForeignKey(
                name: "FK_PlayerGames_Team_TeamId",
                table: "PlayerGames");

            migrationBuilder.DropForeignKey(
                name: "FK_Team_Games_GameName",
                table: "Team");

            migrationBuilder.DropForeignKey(
                name: "FK_Team_Matches_MatchId",
                table: "Team");

            migrationBuilder.DropForeignKey(
                name: "FK_Tournament_Games_GameName",
                table: "Tournament");

            migrationBuilder.DropPrimaryKey(
                name: "PK_Tournament",
                table: "Tournament");

            migrationBuilder.DropIndex(
                name: "IX_Tournament_GameName",
                table: "Tournament");

            migrationBuilder.DropPrimaryKey(
                name: "PK_Team",
                table: "Team");

            migrationBuilder.DropIndex(
                name: "IX_Team_GameName",
                table: "Team");

            migrationBuilder.DropIndex(
                name: "IX_Team_MatchId",
                table: "Team");

            migrationBuilder.DropPrimaryKey(
                name: "PK_PlayerStats",
                table: "PlayerStats");

            migrationBuilder.DropIndex(
                name: "IX_PlayerStats_MatchId",
                table: "PlayerStats");

            migrationBuilder.DropIndex(
                name: "IX_PlayerGames_PlayerUserName",
                table: "PlayerGames");

            migrationBuilder.DropIndex(
                name: "IX_PlayerGames_TeamId",
                table: "PlayerGames");

            migrationBuilder.DropIndex(
                name: "IX_Matches_TournamentId",
                table: "Matches");

            migrationBuilder.DropColumn(
                name: "Id",
                table: "Tournament");

            migrationBuilder.DropColumn(
                name: "Id",
                table: "Team");

            migrationBuilder.DropColumn(
                name: "MatchId",
                table: "Team");

            migrationBuilder.DropColumn(
                name: "Id",
                table: "PlayerStats");

            migrationBuilder.DropColumn(
                name: "TeamId",
                table: "PlayerGames");

            migrationBuilder.DropColumn(
                name: "TournamentId",
                table: "Matches");

            migrationBuilder.RenameColumn(
                name: "PlayerUserName",
                table: "PlayerGames",
                newName: "TeamName");

            migrationBuilder.RenameColumn(
                name: "TeamId",
                table: "Matches",
                newName: "WinnerId");

            migrationBuilder.AlterColumn<string>(
                name: "Name",
                table: "Tournament",
                nullable: false,
                oldClrType: typeof(string),
                oldNullable: true);

            migrationBuilder.AlterColumn<string>(
                name: "GameName",
                table: "Tournament",
                nullable: false,
                oldClrType: typeof(string),
                oldNullable: true);

            migrationBuilder.AlterColumn<string>(
                name: "Name",
                table: "Team",
                nullable: false,
                oldClrType: typeof(string),
                oldNullable: true);

            migrationBuilder.AlterColumn<string>(
                name: "GameName",
                table: "Team",
                nullable: false,
                oldClrType: typeof(string),
                oldNullable: true);

            migrationBuilder.AddColumn<string>(
                name: "PlayerId",
                table: "PlayerGames",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "TeamGameName",
                table: "PlayerGames",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "Team1GameName",
                table: "Matches",
                nullable: true);

            migrationBuilder.AddColumn<int>(
                name: "Team1Id",
                table: "Matches",
                nullable: false,
                defaultValue: 0);

            migrationBuilder.AddColumn<string>(
                name: "Team1Name",
                table: "Matches",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "Team2GameName",
                table: "Matches",
                nullable: true);

            migrationBuilder.AddColumn<int>(
                name: "Team2Id",
                table: "Matches",
                nullable: false,
                defaultValue: 0);

            migrationBuilder.AddColumn<string>(
                name: "Team2Name",
                table: "Matches",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "TournamentGameName",
                table: "Matches",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "TournamentName",
                table: "Matches",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "WinnerGameName",
                table: "Matches",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "WinnerName",
                table: "Matches",
                nullable: true);

            migrationBuilder.AddPrimaryKey(
                name: "PK_Tournament",
                table: "Tournament",
                columns: new[] { "GameName", "Name" });

            migrationBuilder.AddPrimaryKey(
                name: "PK_Team",
                table: "Team",
                columns: new[] { "GameName", "Name" });

            migrationBuilder.AddPrimaryKey(
                name: "PK_PlayerStats",
                table: "PlayerStats",
                columns: new[] { "MatchId", "PlayerGameId" });

            migrationBuilder.CreateIndex(
                name: "IX_PlayerGames_PlayerId",
                table: "PlayerGames",
                column: "PlayerId");

            migrationBuilder.CreateIndex(
                name: "IX_PlayerGames_TeamGameName_TeamName",
                table: "PlayerGames",
                columns: new[] { "TeamGameName", "TeamName" });

            migrationBuilder.CreateIndex(
                name: "IX_Matches_Team1GameName_Team1Name",
                table: "Matches",
                columns: new[] { "Team1GameName", "Team1Name" });

            migrationBuilder.CreateIndex(
                name: "IX_Matches_Team2GameName_Team2Name",
                table: "Matches",
                columns: new[] { "Team2GameName", "Team2Name" });

            migrationBuilder.CreateIndex(
                name: "IX_Matches_TournamentGameName_TournamentName",
                table: "Matches",
                columns: new[] { "TournamentGameName", "TournamentName" });

            migrationBuilder.CreateIndex(
                name: "IX_Matches_WinnerGameName_WinnerName",
                table: "Matches",
                columns: new[] { "WinnerGameName", "WinnerName" });

            migrationBuilder.AddForeignKey(
                name: "FK_Matches_Team_Team1GameName_Team1Name",
                table: "Matches",
                columns: new[] { "Team1GameName", "Team1Name" },
                principalTable: "Team",
                principalColumns: new[] { "GameName", "Name" },
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_Matches_Team_Team2GameName_Team2Name",
                table: "Matches",
                columns: new[] { "Team2GameName", "Team2Name" },
                principalTable: "Team",
                principalColumns: new[] { "GameName", "Name" },
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_Matches_Tournament_TournamentGameName_TournamentName",
                table: "Matches",
                columns: new[] { "TournamentGameName", "TournamentName" },
                principalTable: "Tournament",
                principalColumns: new[] { "GameName", "Name" },
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_Matches_Team_WinnerGameName_WinnerName",
                table: "Matches",
                columns: new[] { "WinnerGameName", "WinnerName" },
                principalTable: "Team",
                principalColumns: new[] { "GameName", "Name" },
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_PlayerGames_Players_PlayerId",
                table: "PlayerGames",
                column: "PlayerId",
                principalTable: "Players",
                principalColumn: "UserName",
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_PlayerGames_Team_TeamGameName_TeamName",
                table: "PlayerGames",
                columns: new[] { "TeamGameName", "TeamName" },
                principalTable: "Team",
                principalColumns: new[] { "GameName", "Name" },
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_Team_Games_GameName",
                table: "Team",
                column: "GameName",
                principalTable: "Games",
                principalColumn: "Name",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_Tournament_Games_GameName",
                table: "Tournament",
                column: "GameName",
                principalTable: "Games",
                principalColumn: "Name",
                onDelete: ReferentialAction.Cascade);
        }
    }
}
<file_sep>﻿using EsportEvent.Domain;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace EsportEvent.Data
{
    public class PlayerRepo : GenericEsportRepo<Player, EsportEventContext>
    {
        public override void Delete(Player player)
        {
            Context.PlayerGames.RemoveRange(player.Games);
            Context.Players.Remove(player);
            Context.SaveChanges();
        }

        public override void DeleteRange(ICollection<Player> entities)
        {

        }

        public override ICollection<Player> FindBy(Expression<Func<Player, bool>> predicate)
        {
            return Context.Players.Where(predicate)
                   .Include(g => g.Games)
                   .ThenInclude(t => t.Team)
                   .ToList();
        }

        public override async Task<ICollection<Player>> FindByAsync(Expression<Func<Player, bool>> predicate)
        {
            return await Context.Players.Where(predicate)
                   .Include(g => g.Games)
                   .ThenInclude(t => t.Team)
                   .ToListAsync();


        }

        public override ICollection<Player> GetAll()
        {
            return Context.Players
                .Include(g => g.Games)
                .ThenInclude(t => t.Team)
                .ToList();
                
        }

        public async override Task<ICollection<Player>> GetAllAsync()
        {
            return await Context.Players
                .Include(g => g.Games)
                .ThenInclude(t => t.Team)
                .ToListAsync();
        }

        public override void Update(Player entity)
        {
            Context.Update(new Player {Name=entity.Name, UserName=entity.UserName });
        }

        public override void UpdateRange(ICollection<Player> entities)
        {
            List<Player> players = entities.ToList();
            for (int i = 0; i< entities.Count; i++)
            {
                Context.Update(new Player { Name = players[i].Name, UserName = players[i].UserName });
            }
        }
    }
}

<file_sep>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using EsportEvent.Domain;

namespace EsportEvent.Data
{
    public class TournamentRepo : GenericEsportRepo<Tournament, EsportEventContext>
    {

    }
}
<file_sep>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using EsportEvent.Domain;
using Microsoft.EntityFrameworkCore;

namespace EsportEvent.Data
{
    public class TeamRepo : GenericEsportRepo<Team, EsportEventContext>
    {
     
        
    }
}
<file_sep>﻿using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace EsportEvent.Data
{
    public abstract class GenericEsportRepo<T, C> where T : class where C : DbContext, new()
    {
        private C _context = new C();
        public C Context
        {
            get { return _context; }
            set { _context = value; }
        }

        public virtual ICollection<T> GetAll()
        {
            return _context.Set<T>().ToList();
        }

        public virtual async Task<ICollection<T>> GetAllAsync() 
        {
            return await _context.Set<T>().ToListAsync();
        }

        public virtual ICollection<T> FindBy(Expression<Func<T, bool>> predicate)
        {
            return _context.Set<T>().Where(predicate).ToList();
        }

        public virtual async Task<ICollection<T>> FindByAsync(Expression<Func<T, bool>> predicate)
        {
            return await _context.Set<T>().ToListAsync();
        }

        public virtual void Add(T entity)
        {
            _context.Set<T>().Add(entity);
        }

        public virtual async void AddAsync(T entity)
        {
            await _context.Set<T>().AddAsync(entity);
        }

        public virtual void AddRange(ICollection<T> entities)
        {
            _context.Set<T>().AddRange(entities);
        }

        public virtual async void AddRangeAsync(ICollection<T> entities)
        {
          await  _context.Set<T>().AddRangeAsync(entities);        
        }


        public virtual void Delete(T entity)
        {
            _context.Set<T>().Remove(entity);
        }

        public virtual void DeleteRange(ICollection<T> entities)
        {
            _context.Set<T>().RemoveRange(entities);
        }

        public virtual void Update(T entity)
        {
            _context.Set<T>().Update(entity);
        }

        public virtual void UpdateRange(ICollection<T> entities)
        {
            _context.Set<T>().UpdateRange(entities);
        }

        public virtual void Save()
        {
            _context.SaveChanges();
        }

        public virtual void SaveAsync()
        {
            _context.SaveChangesAsync();
        }

    }
}
<file_sep>﻿using EsportEvent.Domain;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace EsportEvent.Data
{
    public class GameRepo : GenericEsportRepo<Game, EsportEventContext>
    {
     
    }
}
<file_sep>﻿using Microsoft.EntityFrameworkCore.Migrations;
using System;
using System.Collections.Generic;

namespace EsportEvent.Data.Migrations
{
    public partial class Minorchanges : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_Matches_Tournament_TournamentGameId_TournamentName",
                table: "Matches");

            migrationBuilder.DropForeignKey(
                name: "FK_Team_Tournament_TournamentGameId_TournamentName",
                table: "Team");

            migrationBuilder.DropForeignKey(
                name: "FK_Tournament_Games_Name",
                table: "Tournament");

            migrationBuilder.DropPrimaryKey(
                name: "PK_Tournament",
                table: "Tournament");

            migrationBuilder.DropIndex(
                name: "IX_Tournament_Name",
                table: "Tournament");

            migrationBuilder.DropIndex(
                name: "IX_Team_TournamentGameId_TournamentName",
                table: "Team");

            migrationBuilder.DropIndex(
                name: "IX_Matches_TournamentGameId_TournamentName",
                table: "Matches");

            migrationBuilder.DropColumn(
                name: "GameId",
                table: "Tournament");

            migrationBuilder.DropColumn(
                name: "TournamentGameId",
                table: "Team");

            migrationBuilder.DropColumn(
                name: "TournamentName",
                table: "Team");

            migrationBuilder.DropColumn(
                name: "TournamentGameId",
                table: "Matches");

            migrationBuilder.AddColumn<string>(
                name: "GameName",
                table: "Tournament",
                nullable: false,
                defaultValue: "");

            migrationBuilder.AddColumn<string>(
                name: "TournamentGameName",
                table: "Matches",
                nullable: true);

            migrationBuilder.AddPrimaryKey(
                name: "PK_Tournament",
                table: "Tournament",
                columns: new[] { "GameName", "Name" });

            migrationBuilder.CreateIndex(
                name: "IX_Matches_TournamentGameName_TournamentName",
                table: "Matches",
                columns: new[] { "TournamentGameName", "TournamentName" });

            migrationBuilder.AddForeignKey(
                name: "FK_Matches_Tournament_TournamentGameName_TournamentName",
                table: "Matches",
                columns: new[] { "TournamentGameName", "TournamentName" },
                principalTable: "Tournament",
                principalColumns: new[] { "GameName", "Name" },
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_Tournament_Games_GameName",
                table: "Tournament",
                column: "GameName",
                principalTable: "Games",
                principalColumn: "Name",
                onDelete: ReferentialAction.Cascade);
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_Matches_Tournament_TournamentGameName_TournamentName",
                table: "Matches");

            migrationBuilder.DropForeignKey(
                name: "FK_Tournament_Games_GameName",
                table: "Tournament");

            migrationBuilder.DropPrimaryKey(
                name: "PK_Tournament",
                table: "Tournament");

            migrationBuilder.DropIndex(
                name: "IX_Matches_TournamentGameName_TournamentName",
                table: "Matches");

            migrationBuilder.DropColumn(
                name: "GameName",
                table: "Tournament");

            migrationBuilder.DropColumn(
                name: "TournamentGameName",
                table: "Matches");

            migrationBuilder.AddColumn<int>(
                name: "GameId",
                table: "Tournament",
                nullable: false,
                defaultValue: 0);

            migrationBuilder.AddColumn<int>(
                name: "TournamentGameId",
                table: "Team",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "TournamentName",
                table: "Team",
                nullable: true);

            migrationBuilder.AddColumn<int>(
                name: "TournamentGameId",
                table: "Matches",
                nullable: true);

            migrationBuilder.AddPrimaryKey(
                name: "PK_Tournament",
                table: "Tournament",
                columns: new[] { "GameId", "Name" });

            migrationBuilder.CreateIndex(
                name: "IX_Tournament_Name",
                table: "Tournament",
                column: "Name");

            migrationBuilder.CreateIndex(
                name: "IX_Team_TournamentGameId_TournamentName",
                table: "Team",
                columns: new[] { "TournamentGameId", "TournamentName" });

            migrationBuilder.CreateIndex(
                name: "IX_Matches_TournamentGameId_TournamentName",
                table: "Matches",
                columns: new[] { "TournamentGameId", "TournamentName" });

            migrationBuilder.AddForeignKey(
                name: "FK_Matches_Tournament_TournamentGameId_TournamentName",
                table: "Matches",
                columns: new[] { "TournamentGameId", "TournamentName" },
                principalTable: "Tournament",
                principalColumns: new[] { "GameId", "Name" },
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_Team_Tournament_TournamentGameId_TournamentName",
                table: "Team",
                columns: new[] { "TournamentGameId", "TournamentName" },
                principalTable: "Tournament",
                principalColumns: new[] { "GameId", "Name" },
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_Tournament_Games_Name",
                table: "Tournament",
                column: "Name",
                principalTable: "Games",
                principalColumn: "Name",
                onDelete: ReferentialAction.Cascade);
        }
    }
}
<file_sep>﻿using Microsoft.EntityFrameworkCore.Migrations;
using System;
using System.Collections.Generic;

namespace EsportEvent.Data.Migrations
{
    public partial class minor : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_Matches_Team_Team1GameId_Team1Name",
                table: "Matches");

            migrationBuilder.DropForeignKey(
                name: "FK_Matches_Team_Team2GameId_Team2Name",
                table: "Matches");

            migrationBuilder.DropForeignKey(
                name: "FK_Matches_Team_WinnerGameId_WinnerName",
                table: "Matches");

            migrationBuilder.DropForeignKey(
                name: "FK_PlayerGames_Team_TeamGameId_TeamName",
                table: "PlayerGames");

            migrationBuilder.DropForeignKey(
                name: "FK_Team_Games_Name",
                table: "Team");

            migrationBuilder.DropPrimaryKey(
                name: "PK_Team",
                table: "Team");

            migrationBuilder.DropIndex(
                name: "IX_Team_Name",
                table: "Team");

            migrationBuilder.DropIndex(
                name: "IX_PlayerGames_TeamGameId_TeamName",
                table: "PlayerGames");

            migrationBuilder.DropIndex(
                name: "IX_Matches_Team1GameId_Team1Name",
                table: "Matches");

            migrationBuilder.DropIndex(
                name: "IX_Matches_Team2GameId_Team2Name",
                table: "Matches");

            migrationBuilder.DropIndex(
                name: "IX_Matches_WinnerGameId_WinnerName",
                table: "Matches");

            migrationBuilder.DropColumn(
                name: "GameId",
                table: "Team");

            migrationBuilder.DropColumn(
                name: "GameId",
                table: "PlayerGames");

            migrationBuilder.DropColumn(
                name: "TeamGameId",
                table: "PlayerGames");

            migrationBuilder.DropColumn(
                name: "Team1GameId",
                table: "Matches");

            migrationBuilder.DropColumn(
                name: "Team2GameId",
                table: "Matches");

            migrationBuilder.DropColumn(
                name: "WinnerGameId",
                table: "Matches");

            migrationBuilder.AddColumn<string>(
                name: "GameName",
                table: "Team",
                nullable: false,
                defaultValue: "");

            migrationBuilder.AddColumn<string>(
                name: "TeamGameName",
                table: "PlayerGames",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "Team1GameName",
                table: "Matches",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "Team2GameName",
                table: "Matches",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "WinnerGameName",
                table: "Matches",
                nullable: true);

            migrationBuilder.AddPrimaryKey(
                name: "PK_Team",
                table: "Team",
                columns: new[] { "GameName", "Name" });

            migrationBuilder.CreateIndex(
                name: "IX_PlayerGames_TeamGameName_TeamName",
                table: "PlayerGames",
                columns: new[] { "TeamGameName", "TeamName" });

            migrationBuilder.CreateIndex(
                name: "IX_Matches_Team1GameName_Team1Name",
                table: "Matches",
                columns: new[] { "Team1GameName", "Team1Name" });

            migrationBuilder.CreateIndex(
                name: "IX_Matches_Team2GameName_Team2Name",
                table: "Matches",
                columns: new[] { "Team2GameName", "Team2Name" });

            migrationBuilder.CreateIndex(
                name: "IX_Matches_WinnerGameName_WinnerName",
                table: "Matches",
                columns: new[] { "WinnerGameName", "WinnerName" });

            migrationBuilder.AddForeignKey(
                name: "FK_Matches_Team_Team1GameName_Team1Name",
                table: "Matches",
                columns: new[] { "Team1GameName", "Team1Name" },
                principalTable: "Team",
                principalColumns: new[] { "GameName", "Name" },
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_Matches_Team_Team2GameName_Team2Name",
                table: "Matches",
                columns: new[] { "Team2GameName", "Team2Name" },
                principalTable: "Team",
                principalColumns: new[] { "GameName", "Name" },
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_Matches_Team_WinnerGameName_WinnerName",
                table: "Matches",
                columns: new[] { "WinnerGameName", "WinnerName" },
                principalTable: "Team",
                principalColumns: new[] { "GameName", "Name" },
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_PlayerGames_Team_TeamGameName_TeamName",
                table: "PlayerGames",
                columns: new[] { "TeamGameName", "TeamName" },
                principalTable: "Team",
                principalColumns: new[] { "GameName", "Name" },
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_Team_Games_GameName",
                table: "Team",
                column: "GameName",
                principalTable: "Games",
                principalColumn: "Name",
                onDelete: ReferentialAction.Cascade);
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_Matches_Team_Team1GameName_Team1Name",
                table: "Matches");

            migrationBuilder.DropForeignKey(
                name: "FK_Matches_Team_Team2GameName_Team2Name",
                table: "Matches");

            migrationBuilder.DropForeignKey(
                name: "FK_Matches_Team_WinnerGameName_WinnerName",
                table: "Matches");

            migrationBuilder.DropForeignKey(
                name: "FK_PlayerGames_Team_TeamGameName_TeamName",
                table: "PlayerGames");

            migrationBuilder.DropForeignKey(
                name: "FK_Team_Games_GameName",
                table: "Team");

            migrationBuilder.DropPrimaryKey(
                name: "PK_Team",
                table: "Team");

            migrationBuilder.DropIndex(
                name: "IX_PlayerGames_TeamGameName_TeamName",
                table: "PlayerGames");

            migrationBuilder.DropIndex(
                name: "IX_Matches_Team1GameName_Team1Name",
                table: "Matches");

            migrationBuilder.DropIndex(
                name: "IX_Matches_Team2GameName_Team2Name",
                table: "Matches");

            migrationBuilder.DropIndex(
                name: "IX_Matches_WinnerGameName_WinnerName",
                table: "Matches");

            migrationBuilder.DropColumn(
                name: "GameName",
                table: "Team");

            migrationBuilder.DropColumn(
                name: "TeamGameName",
                table: "PlayerGames");

            migrationBuilder.DropColumn(
                name: "Team1GameName",
                table: "Matches");

            migrationBuilder.DropColumn(
                name: "Team2GameName",
                table: "Matches");

            migrationBuilder.DropColumn(
                name: "WinnerGameName",
                table: "Matches");

            migrationBuilder.AddColumn<int>(
                name: "GameId",
                table: "Team",
                nullable: false,
                defaultValue: 0);

            migrationBuilder.AddColumn<int>(
                name: "GameId",
                table: "PlayerGames",
                nullable: false,
                defaultValue: 0);

            migrationBuilder.AddColumn<int>(
                name: "TeamGameId",
                table: "PlayerGames",
                nullable: true);

            migrationBuilder.AddColumn<int>(
                name: "Team1GameId",
                table: "Matches",
                nullable: true);

            migrationBuilder.AddColumn<int>(
                name: "Team2GameId",
                table: "Matches",
                nullable: true);

            migrationBuilder.AddColumn<int>(
                name: "WinnerGameId",
                table: "Matches",
                nullable: true);

            migrationBuilder.AddPrimaryKey(
                name: "PK_Team",
                table: "Team",
                columns: new[] { "GameId", "Name" });

            migrationBuilder.CreateIndex(
                name: "IX_Team_Name",
                table: "Team",
                column: "Name");

            migrationBuilder.CreateIndex(
                name: "IX_PlayerGames_TeamGameId_TeamName",
                table: "PlayerGames",
                columns: new[] { "TeamGameId", "TeamName" });

            migrationBuilder.CreateIndex(
                name: "IX_Matches_Team1GameId_Team1Name",
                table: "Matches",
                columns: new[] { "Team1GameId", "Team1Name" });

            migrationBuilder.CreateIndex(
                name: "IX_Matches_Team2GameId_Team2Name",
                table: "Matches",
                columns: new[] { "Team2GameId", "Team2Name" });

            migrationBuilder.CreateIndex(
                name: "IX_Matches_WinnerGameId_WinnerName",
                table: "Matches",
                columns: new[] { "WinnerGameId", "WinnerName" });

            migrationBuilder.AddForeignKey(
                name: "FK_Matches_Team_Team1GameId_Team1Name",
                table: "Matches",
                columns: new[] { "Team1GameId", "Team1Name" },
                principalTable: "Team",
                principalColumns: new[] { "GameId", "Name" },
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_Matches_Team_Team2GameId_Team2Name",
                table: "Matches",
                columns: new[] { "Team2GameId", "Team2Name" },
                principalTable: "Team",
                principalColumns: new[] { "GameId", "Name" },
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_Matches_Team_WinnerGameId_WinnerName",
                table: "Matches",
                columns: new[] { "WinnerGameId", "WinnerName" },
                principalTable: "Team",
                principalColumns: new[] { "GameId", "Name" },
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_PlayerGames_Team_TeamGameId_TeamName",
                table: "PlayerGames",
                columns: new[] { "TeamGameId", "TeamName" },
                principalTable: "Team",
                principalColumns: new[] { "GameId", "Name" },
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_Team_Games_Name",
                table: "Team",
                column: "Name",
                principalTable: "Games",
                principalColumn: "Name",
                onDelete: ReferentialAction.Cascade);
        }
    }
}
<file_sep>﻿using EsportEvent.Domain;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace EsportEvent.Data
{
    public class MatchRepo : GenericEsportRepo<Match, EsportEventContext>
    {


        public override ICollection<Match> GetAll()
        {
            return Context.Matches
                .Include(t => t.Game)
                .Include(p => p.PlayerStats)
                .Include(t => t.Teams)
                .ToList();               
        }

        public override Task<ICollection<Match>> GetAllAsync()
        {
            return base.GetAllAsync();
        }
        public override ICollection<Match> FindBy(Expression<Func<Match, bool>> predicate)
        {
            return base.FindBy(predicate);
        }
        public override Task<ICollection<Match>> FindByAsync(Expression<Func<Match, bool>> predicate)
        {
            return base.FindByAsync(predicate);
        }

        //__________________________________________________________________

        public override void Add(Match entity)
        {
            TeamMatchRepo teamMatch = new TeamMatchRepo();
            var match = new Match
            {
                GameName = entity.GameName,
                GameDay = entity.GameDay,
                TournamentId = entity.TournamentId
            };

            Context.Add(match);

            Save();
            teamMatch.AddRange(new List<TeamMatch>
            {
                new TeamMatch{MatchId=match.Id, TeamId = entity.Teams[0].Id},
                new TeamMatch{MatchId=match.Id, TeamId = entity.Teams[1].Id }
            });
            teamMatch.Save();
        }

        public override async void AddAsync(Match entity)
        {
            TeamMatchRepo teamMatch = new TeamMatchRepo();
           await Context.AddAsync(new Match
            {
                GameName = entity.GameName,
                GameDay = entity.GameDay,
                TournamentId = entity.Id,
            });
            SaveAsync();

            Task.WaitAll();
             teamMatch.AddRangeAsync(new List<TeamMatch>
            {
                new TeamMatch{MatchId=entity.Id, TeamId=entity.Teams[0].Id},
                new TeamMatch{MatchId=entity.Id, TeamId = entity.Teams[1].Id }
            });
        }

        public override void AddRange(ICollection<Match> entities)
        {
            var list = entities.ToList();

            for (int i = 0; i < entities.Count; i++)
            {
                TeamMatchRepo teamMatch = new TeamMatchRepo();
                Context.Add(new Match
                {
                    GameName = list[i].GameName,
                    GameDay = list[i].GameDay,
                    TournamentId = list[i].Id,
                });
                Save();
                teamMatch.AddRange(new List<TeamMatch>
            {
                new TeamMatch{MatchId=list[i].Id, TeamId=list[i].Teams[0].Id},
                new TeamMatch{MatchId=list[i].Id, TeamId = list[i].Teams[1].Id }
            });
            }
        }

        public override async void AddRangeAsync(ICollection<Match> entities)
        {
            var list = entities.ToList();

            for (int i = 0; i < entities.Count; i++)
            {
                TeamMatchRepo teamMatch = new TeamMatchRepo();
                await Context.AddAsync(new Match
                {
                    GameName = list[i].GameName,
                    GameDay = list[i].GameDay,
                    TournamentId = list[i].Id,
                });
                Save();
                Task.WaitAll();
                teamMatch.AddRange(new List<TeamMatch>
                {
                    new TeamMatch{MatchId=list[i].Id, TeamId=list[i].Teams[0].Id},
                    new TeamMatch{MatchId=list[i].Id, TeamId = list[i].Teams[1].Id }
                 });
            }
        }

    }
}
