Ejemplo n.º 1
0
        public async Task <IEnumerable <List <StandingsViewModel> > > GetStandingsByChampionshipId(int id)
        {
            List <List <StandingsViewModel> > standingsList = new List <List <StandingsViewModel> >();
            List <Subscription> subscriptionList            = new List <Subscription>();

            var championship = await _championshipRepository.GetById(id);

            if (championship.ChampionshipType == ChampionshipType.PontosCorridos)
            {
                var result = await _subscriptionRepository.GetAll();

                subscriptionList = result.Where(p => p.ChampionshipId == id).OrderBy(p => p.Team.Name).ToList();

                standingsList.Add(await GetStandingsBySubscriptions(subscriptionList));
            }
            else
            {
                var result = await _groupChampionshipRepository.GetAll();

                foreach (Group group in (Group[])Enum.GetValues(typeof(Group)))
                {
                    var groupChampionship = result.Where(p => p.Subscription.ChampionshipId == id && p.GroupId == group);

                    foreach (var item in groupChampionship)
                    {
                        subscriptionList.Add(item.Subscription);
                    }

                    if (subscriptionList.Count() == 0)
                    {
                        break;
                    }

                    standingsList.Add(await GetStandingsBySubscriptions(subscriptionList));

                    subscriptionList.Clear();
                }
            }

            return(standingsList);
        }
        public void AutomaticMatchChampionship(int championshipId, int groupId)
        {
            Random rnd          = new Random();
            int    quantityTeam = 0;
            int    round        = 0;
            int    count        = 0;
            int    turno        = 0;
            int    fieldId      = 0;

            List <int> teamSubscription = new List <int>();

            string[] matchs;


            var championship = _championshipRepository.GetById(championshipId).Result;

            switch (championship.ChampionshipType)
            {
            case ChampionshipType.Grupos:
                if (groupId == 0)
                {
                    throw new Exception();
                }
                else
                {
                    var resultGroupChampionship = _groupChampionshipRepository.GetAll().Result;
                    var groupChampionship       = resultGroupChampionship.Where(p => p.GroupId == (Group)groupId && p.Subscription.ChampionshipId == championshipId).ToList();

                    foreach (var e in groupChampionship)
                    {
                        teamSubscription.Add(e.SubscriptionId);
                        fieldId = e.Subscription.Championship.FieldId;
                    }
                }
                break;

            case ChampionshipType.MataMata:
                break;

            case ChampionshipType.PontosCorridos:
                var result        = _subscriptionRepository.GetAll().Result;
                var subscriptions = result.Where(p => p.ChampionshipId == championshipId);

                foreach (var e in subscriptions)
                {
                    teamSubscription.Add(e.Id);
                    fieldId = e.Championship.FieldId;
                }
                break;

            default:
                break;
            }

            quantityTeam = teamSubscription.Count();

            if (quantityTeam % 2 == 0)
            {
                round = quantityTeam - 1;
            }
            else
            {
                round = quantityTeam;
            }

            if (championship.GoBack)
            {
                turno  = 2;
                matchs = new string[Divers.CalculaFatorial(quantityTeam) / Divers.CalculaFatorial(quantityTeam - 2)];
            }
            else
            {
                turno  = 1;
                matchs = new string[Divers.CalculaFatorial(quantityTeam) / Divers.CalculaFatorial(quantityTeam - 2) / 2];
            }

            count = 0;

            for (int t = 0; t < turno; t++)
            {
                for (int i = 0; i < quantityTeam; i++)
                {     //For para caminhar entre os times
                    for (int j = i; j < quantityTeam; j++)
                    { //For para caminha entre os adversários
                        if (teamSubscription[i] != teamSubscription[j])
                        {
                            MatchChampionship matchChampionship = new MatchChampionship
                            {
                                HomeSubscriptionId  = teamSubscription[i],
                                GuestSubscriptionId = teamSubscription[j],
                                HomePoints          = 0,
                                GuestPoints         = 0,
                                MatchDate           = DateTime.Now,
                                RegisterDate        = DateTime.Now,
                                StartTime           = "",
                                Round = 0
                            };

                            _matchChampionshipRepository.Add(matchChampionship);

                            //Sumula sumula = new Sumula();

                            //sumula.IDPartidaCampeonato = partidaCampeonato.IDPartidaCampeonato;
                            //sumula.sObservacao = "";
                            //sumula.dDataCadastro = DateTime.Now;
                            //db.Sumula.Add(sumula);
                            //db.SaveChanges();
                        }
                    }
                }
            }

            if (quantityTeam % 2 == 0)
            {
                OrdenaRodada(championshipId, teamSubscription);
            }
            else
            {
                List <int> timesInscritosNew = new List <int>();

                foreach (int e in teamSubscription)
                {
                    timesInscritosNew[count] = e;
                    count++;
                }

                timesInscritosNew[teamSubscription.Count()] = 10000000;

                OrdenaRodada(championshipId, timesInscritosNew);
            }
        }
Ejemplo n.º 3
0
 public async Task <ChampionshipViewModel> GetById(int id)
 {
     return(_mapper.Map <ChampionshipViewModel>(await _championshipRepository.GetById(id)));
 }
Ejemplo n.º 4
0
        public async Task <IEnumerable <SuspendedPlayersViewModel> > GetSuspendedPlayersByChampionshipId(int id, int rodada)
        {
            List <SuspendedPlayersViewModel> suspendedPlayersList = new List <SuspendedPlayersViewModel>();

            var championship = await _championshipRepository.GetById(id);

            rodada -= 1;

            List <MatchPlayerChampionship> partidasCartaoAmarelo, partidasCartaoVermelho;

            var matchPlayerChampionships = await _matchPlayerChampionshipsRepository.GetAll();

            if (championship.RefereeType == RefereeType.Campo)
            {
                List <SuspendedPlayersViewModel> jsl = new List <SuspendedPlayersViewModel>();

                for (int i = 1; i <= rodada; i++)
                {
                    partidasCartaoAmarelo = matchPlayerChampionships
                                            .Where(p => p.Card == CardType.Yellow || p.Card == CardType.YellowSecond || p.Card == CardType.RedYellow)
                                            .Where(s => s.MatchChampionship.Round == i && s.PlayerRegistration.Subscription.ChampionshipId == id).ToList();

                    foreach (var item in partidasCartaoAmarelo)
                    {
                        suspendedPlayersList.Add(new SuspendedPlayersViewModel {
                            Id = item.PlayerRegistrationId, Player = item.PlayerRegistration.Player.Name, Team = item.PlayerRegistration.Subscription.Team.Name
                        });
                    }

                    var groupJogador = suspendedPlayersList.GroupBy(p => p.Id).Select(grp => new
                    {
                        Id = grp.Key,
                        grp.First().Player,
                        grp.First().Team
                    })
                                       .ToArray();

                    foreach (var item in groupJogador)
                    {
                        int qntCartaoJogador = suspendedPlayersList.Where(p => p.Id == item.Id).ToList().Count;

                        if (qntCartaoJogador >= 3)
                        {
                            if (qntCartaoJogador % 3 == 0)
                            {
                                SuspendedPlayersViewModel suspendedPlayersViewModel = new SuspendedPlayersViewModel
                                {
                                    Player = item.Player,
                                    Team   = item.Team
                                };

                                jsl.Add(suspendedPlayersViewModel);

                                suspendedPlayersList.RemoveAll(jc => jc.Id == item.Id);
                            }
                        }
                    }

                    partidasCartaoVermelho = matchPlayerChampionships
                                             .Where(p => p.Card == CardType.Red || p.Card == CardType.YellowSecond || p.Card == CardType.RedYellow)
                                             .Where(s => s.MatchChampionship.Round == i && s.PlayerRegistration.Subscription.ChampionshipId == id).ToList();

                    foreach (var item in partidasCartaoVermelho)
                    {
                        SuspendedPlayersViewModel suspendedPlayersViewModel = new SuspendedPlayersViewModel
                        {
                            Player = item.PlayerRegistration.Player.Name,
                            Team   = item.PlayerRegistration.Subscription.Team.Name
                        };

                        jsl.Add(suspendedPlayersViewModel);
                    }
                }

                suspendedPlayersList = jsl;
            }
            else
            {
                partidasCartaoVermelho = matchPlayerChampionships
                                         .Where(p => p.Card == CardType.Red || p.Card == CardType.YellowSecond || p.Card == CardType.RedYellow)
                                         .Where(s => s.MatchChampionship.Round == rodada && s.PlayerRegistration.Subscription.ChampionshipId == id).ToList();

                foreach (var item in partidasCartaoVermelho)
                {
                    SuspendedPlayersViewModel suspendedPlayersViewModel = new SuspendedPlayersViewModel
                    {
                        Player = item.PlayerRegistration.Player.Name,
                        Team   = item.PlayerRegistration.Subscription.Team.Name
                    };

                    suspendedPlayersList.Add(suspendedPlayersViewModel);
                }
            }

            return(suspendedPlayersList);
        }