public void GetAllEncountersOfTeamTest()
        {
            ICollection <EncountersTeams> teams = new List <EncountersTeams>()
            {
                eNacional, ePeƱarol
            };
            var encounter = new Encounter()
            {
                Id = 1, Date = DateTime.Now, SportId = football.Id, Teams = teams
            };

            encounterList.Add(encounter);
            encounterBL.GetAllEncountersOfTeam(nacional.Id);
            mockEncounterRepo.Verify(x => x.Get(It.IsAny <Expression <Func <Encounter, bool> > >(), null, "Results"), Times.Once());
        }
        public ICollection <Score> GeneratePositionTableForSport(int sportId)
        {
            ICollection <Score> positions = new List <Score>();
            Sport       sport             = sportBL.GetById(sportId);
            List <Team> teams             = sport.Teams.ToList();

            foreach (Team team in teams)
            {
                List <Encounter> encounters = encounterBL.GetAllEncountersOfTeam(team.Id).ToList();
                Score            position   = new Score()
                {
                    Team = team
                };
                foreach (Encounter encounter in encounters)
                {
                    if (encounter.Results.Count > 0)
                    {
                        int teamPosition = encounter.Results.FirstOrDefault(t => t.TeamId == team.Id).Position;
                        if (sport.EncounterMode == EncounterMode.Double)
                        {
                            if (teamPosition == 2)
                            {
                                position.Points += 3;
                            }
                            else if (teamPosition == 1)
                            {
                                position.Points += 1;
                            }
                        }
                        else if (sport.EncounterMode == EncounterMode.Multiple)
                        {
                            if (teamPosition == 1)
                            {
                                position.Points += 3;
                            }
                            else if (teamPosition == 2)
                            {
                                position.Points += 2;
                            }
                            else if (teamPosition == 3)
                            {
                                position.Points += 1;
                            }
                        }
                    }
                }
                positions.Add(position);
            }
            return(positions);
        }
Example #3
0
        public ActionResult <ICollection <EncounterDTO> > GetAllEncountersOfTeam(int teamId)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                var encounters = mapper.Map <EncounterDTO[]>(encounterBusinessLogic.GetAllEncountersOfTeam(teamId));
                return(Ok(encounters));
            }
            catch (NoEncountersFoundForTeamException e)
            {
                return(NotFound(e.Message));
            }
            catch (Exception e)
            {
                return(StatusCode(500, e.Message));
            }
        }