Exemplo n.º 1
0
        private void SaveMatchEventsFromMatch(Match match, List <MatchEvent> matchEvents)
        {
            var personService     = new PersonService();
            var teamService       = new TeamService();
            var matchEventService = new MatchEventService();

            foreach (var e in matchEvents)
            {
                var person = personService.FindPlayerById(e.PlayerId);
                matchEventService.Add(e);
                match.MatchEventIds.Add(e.Id);
                person.MatchEvents.Add(e.Id);


                if (e.GetType() != MatchEvents.Goal)
                {
                    continue;
                }

                var goal = (Goal)e;
                Trace.WriteLine(goal.TeamId);
                var team = teamService.FindById(goal.TeamId);
                AddGoalMadeAndConcedToTeams(team, match, goal);
            }

            personService.Save();
        }
Exemplo n.º 2
0
        private void RemoveMatchEventsFromPlayersInMatch(Match match)
        {
            var personSerivce     = new PersonService();
            var matchEventService = new MatchEventService();
            var matchWeekService  = new MatchWeekService();


            foreach (var matchEventId in match.MatchEventIds)
            {
                var mEvent = matchEventService.FindById(matchEventId);
                var player = personSerivce.FindPlayerById(mEvent.PlayerId);

                var matchEvents = player.MatchEvents
                                  .Select(matchEventService.FindById)
                                  .Where(e => e.MatchId == match.Id).ToList();


                var yellowCards = 0;
                foreach (var matchEvent in matchEvents)
                {
                    var type = matchEvent.GetType();

                    if (type == MatchEvents.RedCard)
                    {
                        matchWeekService.RemoveSuspension(3, player, match.Id);
                    }
                    if (type == MatchEvents.YellowCard)
                    {
                        yellowCards++;
                    }

                    player.MatchEvents.Remove(matchEvent.Id);
                }

                if (yellowCards > 1)
                {
                    matchWeekService.RemoveSuspension(1, player, match.Id);
                }
            }

            personSerivce.Save();
        }
Exemplo n.º 3
0
        private void GetAllCardsAndSuspenPlayers(Match match, List <Player> listOfAllPlayes)
        {
            var matchEventService = new MatchEventService();

            foreach (var player in listOfAllPlayes)
            {
                var redCards = match.MatchEventIds
                               .Select(eventId => matchEventService.FindById(eventId))
                               .Where(mEvent => mEvent.GetType() == MatchEvents.RedCard && player.Id == mEvent.PlayerId).ToList();
                var yellowCards = match.MatchEventIds
                                  .Select(eventId => matchEventService.FindById(eventId))
                                  .Where(mEvent => mEvent.GetType() == MatchEvents.YellowCard && player.Id == mEvent.PlayerId)
                                  .ToList();

                if (yellowCards.Count == 0 && redCards.Count == 0)
                {
                    continue;
                }

                new MatchWeekService().SetSuspensionLength(yellowCards.Count, redCards.Count, player, match.Id);
            }
        }