private async Task <Models.Db.Player> CreatePlayer(IDbConnection c, IDbTransaction t, FootballData.Player player, Models.Db.Team dbTeam, long idTournament)
        {
            var(name, surname) = SplitPlayerName(player.Name);

            var dbUser = new Models.Db.User
            {
                Name     = player.Name,
                Level    = (int)UserLevel.Player,
                Salt     = "",
                Password = "",
                Email    = "*****@*****.**",
                Mobile   = "123456789"
            };

            dbUser.Id = await c.InsertAsync(dbUser, t);

            var(fieldPosition, fieldSide) = GetPlayerPosition(player.Position);

            var dbPlayer = new Models.Db.Player
            {
                Name      = name,
                Surname   = surname,
                IdUser    = dbUser.Id,
                BirthDate = player.DateOfBirth.GetValueOrDefault().DateTime,
                Country   = player.Nationality,
                UserData  = dbUser
            };

            dbPlayer.Id = await c.InsertAsync(dbPlayer, t);

            player.DbId = dbPlayer.Id;

            var dbTeamPlayer = new TeamPlayer
            {
                IdPlayer      = dbPlayer.Id,
                IdTeam        = dbTeam.Id,
                ApparelNumber = player.JerseyNumber.GetValueOrDefault(),
                FieldPosition = fieldPosition,
                FieldSide     = fieldSide,
                IsTeamAdmin   = false,
                Status        = 256
            };

            dbPlayer.TeamData = dbTeamPlayer;

            await c.InsertAsync(dbTeamPlayer, t);

            return(dbPlayer);
        }
        private static async Task CreateEvent(IDbConnection c, IDbTransaction t, Match dbMatch, List <MatchEvent> events, Models.Db.Team team, Models.Db.Player player, MatchEventType type, int minuteOffset)
        {
            var ev = new MatchEvent
            {
                IdDay       = dbMatch.IdDay,
                IdMatch     = dbMatch.Id,
                IdTeam      = (team != null ? team.Id : 0),
                IdPlayer    = (player != null ? player.Id : 0),
                MatchMinute = new Random().Next(0 + minuteOffset, 45 + minuteOffset),
                Type        = (int)type,
            };

            ev.Id = await c.InsertAsync(ev, t);

            events.Add(ev);
        }
        private static async Task CreateMatchPlayer(IDbConnection c, IDbTransaction t, Match dbMatch, Models.Db.Team team, Models.Db.Player player)
        {
            // Check apparelnumber
            var dbMatchPlayer = new MatchPlayer
            {
                IdMatch       = dbMatch.Id,
                IdPlayer      = player.Id,
                IdTeam        = team.Id,
                IdUser        = player.IdUser,
                ApparelNumber = player.TeamData.ApparelNumber,
                IdDay         = dbMatch.IdDay,
                Player        = player,
                Status        = 1
            };

            await c.InsertAsync(dbMatchPlayer, t);
        }