예제 #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);
            }
        }
예제 #3
0
        public async Task <IEnumerable <GroupChampionshipViewModel> > GetAll()
        {
            var result = await _groupChampionshipRepository.GetAll();

            return(result.Select(_mapper.Map <GroupChampionshipViewModel>));
        }