public async Task <int> CreateCode(AddCompetitor addCompetitor)
        {
            var Code = new Domain.Code.Code(addCompetitor.confirmationCode, addCompetitor.firstName, addCompetitor.lastName, addCompetitor.legueId, addCompetitor.Ranking);
            int Id   = await _codeRepository.AddCode(Code);

            return(Id);
        }
        public async Task <int> AddCode(Domain.Code.Code code)
        {
            var legueExist = _context.League.Where(b => b.LeagueId == code.LegueId).FirstOrDefault();

            if (legueExist == null && code.LegueId != 0)
            {
                return(-1);
            }
            var competitor = new DAO.CompetitorData
            {
                FirstName = code.FirstName,
                LastName  = code.LastName,
                LeagueId  = code.LegueId,
            };
            await _context.AddAsync(competitor);

            await _context.SaveChangesAsync();

            if (code.LegueId != 0)
            {
                var LastPLayer = _context.LeagueTable.OrderBy(k => k.Points).FirstOrDefault();
                int position   = 1;
                if (LastPLayer != null)
                {
                    position = LastPLayer.Position;
                    if (LastPLayer.Points != 0)
                    {
                        position += 1;
                    }
                }
                LeagueTable league = new LeagueTable()
                {
                    CompetitorDataId = competitor.CompetitorDataId,
                    MatechesWon      = 0,
                    MatchesLoss      = 0,
                    SetsWon          = 0,
                    SetsLoss         = 0,
                    Points           = 0,
                    Position         = position,
                    LeagueId         = code.LegueId
                };
                await _context.AddAsync(league);
            }
            if (code.Competition)
            {
                var LastPLayer = _context.RankingTable.OrderByDescending(k => k.Position).FirstOrDefault();
                int position   = 1;
                if (LastPLayer != null)
                {
                    position = LastPLayer.Position + 1;
                }
                RankingTable league = new RankingTable()
                {
                    CompetitorDataId = competitor.CompetitorDataId,
                    MatechesWon      = 0,
                    MetchesLoss      = 0,
                    Position         = position
                };
                await _context.AddAsync(league);
            }

            await _context.SaveChangesAsync();

            return(competitor.CompetitorDataId);
        }