Esempio n. 1
0
        public List <dbPlayerPrize> GetPrizeAssignments(Event thisEvent, int round)
        {
            var prizeAssignments = new List <dbPlayerPrize>();
            var sortedPlayers    = thisEvent.Players.OrderByDescending(p => p.Score(round)).ThenByDescending(p => p.OMWP(round)).ThenByDescending(p => p.GWP(round)).ThenByDescending(p => p.OGWP(round));

            var prizes = _roundPrizeRepository.LoadDBRoundPrizes(thisEvent.name);

            prizeAssignments = sortedPlayers.Select((p, index) =>
            {
                var thisPrize = prizes.FirstOrDefault(prize => prize.EventName == thisEvent.name && prize.Round == round && prize.Position == index + 1);
                if (thisPrize != null)
                {
                    return(new dbPlayerPrize
                    {
                        EventName = thisEvent.name,
                        Notes = thisPrize.Other,
                        Position = index + 1,
                        Packs = thisPrize.Packs,
                        Round = round,
                        Player = p.Name,
                        PlayerID = p.ID,
                        Recieved = 0
                    });
                }
                else
                {
                    return(null);
                }
            }).OfType <dbPlayerPrize>().ToList();

            return(prizeAssignments);
        }
Esempio n. 2
0
        public void PopulateEvent(Event pop, dbEvent loadedEvent)
        {
            pop.name           = loadedEvent.Name;
            pop.myDbEvent      = loadedEvent;
            pop.rounds         = loadedEvent.Rounds;
            pop.CurrentRound   = loadedEvent.CurrentRound;
            pop.RoundMatches   = loadedEvent.RoundMatches;
            pop.EventStartDate = loadedEvent.StartDate;
            pop.RoundEndDate   = loadedEvent.RoundEndDate;

            var eventPlayers = _eventPlayerRepository.LoadDBEventPlayers(loadedEvent.Name);

            pop.RoundPrizes = _roundPrizeRepository.LoadDBRoundPrizes(loadedEvent.Name);


            //LoadPlayers
            pop.Players = new List <Player>();
            _playerRepository.LoadDBPlayers().Where(p => eventPlayers.Any(ep => ep.PlayerID == p.ID)).ToList().ForEach(p => pop.Players.Add(new Player(p.Name, p.Email, p.ID)));

            //LoadEventPlayers
            eventPlayers.Where(ep => ep.Dropped > 0).ToList().ForEach(ep =>
            {
                foreach (var p in pop.Players)
                {
                    if (p.ID == ep.PlayerID)
                    {
                        p.DroppedInRound = ep.Dropped;
                    }
                }
            });

            //LoadMatches
            pop.Matches = new List <Match>();
            _matchRepository.LoadDBMatches(pop.name).Where(m => m.Event == loadedEvent.Name).ToList().ForEach(m => pop.Matches.Add(m));

            foreach (Match m in pop.Matches)
            {
                _matchRepository.PopulateMatch(pop.Players, m);
            }

            foreach (var match in pop.Matches)
            {
                if (String.IsNullOrEmpty((match.Player1.Name)))
                {
                    throw new Exception();
                }

                if (String.IsNullOrEmpty((match.Player2.Name)))
                {
                    throw new Exception();
                }
            }

            foreach (var p in pop.Players)
            {
                foreach (var m in pop.Matches)
                {
                    if (m.Player1ID == p.ID)
                    {
                        m.Player1 = p;
                        p.Matches.Add(m);
                    }

                    else if (m.Player2ID == p.ID)
                    {
                        m.Player2 = p;
                        p.Matches.Add(m);
                    }
                }
            }
        }