public bool UpdateTournamentPositionTable(TournamentPositionTableDto tournamentPositionTableDto)
        {
            bool response;
            TournamentPositionTable tournamentPositionTable = CreateTournamentPositionTable(tournamentPositionTableDto);

            using (FifaPslTournamentsModel objEntities = new FifaPslTournamentsModel())
            {
                objEntities.TournamentPositionTable.Add(tournamentPositionTable);
                objEntities.Entry(tournamentPositionTable).State = System.Data.Entity.EntityState.Modified;
                objEntities.SaveChanges();

                response = true;
            }

            return(response);
        }
        private TournamentPositionTable CreateTournamentPositionTable(TournamentPositionTableDto tournamentPositionTableDto)
        {
            TournamentPositionTable tournamentPositionTable = new TournamentPositionTable();

            tournamentPositionTable.Id = tournamentPositionTableDto.Id;
            tournamentPositionTable.IdTournamentTeamGroup = tournamentPositionTableDto.IdTournamentTeamGroup;
            tournamentPositionTable.PlayedMatches         = tournamentPositionTableDto.PlayedMatches;
            tournamentPositionTable.WonMatches            = tournamentPositionTableDto.WonMatches;
            tournamentPositionTable.TiedMatches           = tournamentPositionTableDto.TiedMatches;
            tournamentPositionTable.LostMatches           = tournamentPositionTableDto.LostMatches;
            tournamentPositionTable.GoalsScored           = tournamentPositionTableDto.GoalsScored;
            tournamentPositionTable.GoalsReceived         = tournamentPositionTableDto.GoalsReceived;
            tournamentPositionTable.GoalsDifference       = tournamentPositionTableDto.GoalsDifference;
            tournamentPositionTable.Points   = tournamentPositionTableDto.Points;
            tournamentPositionTable.Position = tournamentPositionTableDto.Position;
            return(tournamentPositionTable);
        }
Ejemplo n.º 3
0
        public List <TournamentPositionTableDto> CalculatePositions(List <MatchDto> matchesByGroup, int groupId)
        {
            List <TournamentPositionTableDto> tournamentPositionTablesToReturn = new List <TournamentPositionTableDto>();
            List <TournamentPositionTableDto> tournamentPositionTables         = GetAllTournamentPostionTables();
            List <TournamentPositionTableDto> tournamentPositionTablesByGroup  = tournamentPositionTables.FindAll(x => x.TournamentTeamGroup.IdGroup == groupId);

            foreach (var tournamentPositionTable in tournamentPositionTablesByGroup)
            {
                List <MatchDto> matchesPlayedByTeam = matchesByGroup.FindAll(x => (x.IdLocalTeam == tournamentPositionTable.IdTournamentTeamGroup || x.IdVisitorTeam == tournamentPositionTable.IdTournamentTeamGroup) && x.Played);

                TournamentPositionTableDto tournamentPositionTableDto = new TournamentPositionTableDto();
                tournamentPositionTableDto.Id = tournamentPositionTable.Id;
                tournamentPositionTableDto.IdTournamentTeamGroup = tournamentPositionTable.IdTournamentTeamGroup;
                tournamentPositionTableDto.PlayedMatches         = matchesPlayedByTeam.Count();
                tournamentPositionTableDto.WonMatches            = matchesPlayedByTeam.Where(x => (x.IdLocalTeam == tournamentPositionTable.IdTournamentTeamGroup && x.LocalTeamScore > x.VisitorTeamScore) ||
                                                                                             (x.IdVisitorTeam == tournamentPositionTable.IdTournamentTeamGroup && x.LocalTeamScore < x.VisitorTeamScore)).Count();
                tournamentPositionTableDto.TiedMatches = matchesPlayedByTeam.Where(x => x.LocalTeamScore == x.VisitorTeamScore).Count();
                tournamentPositionTableDto.LostMatches = matchesPlayedByTeam.Where(x => (x.IdLocalTeam == tournamentPositionTable.IdTournamentTeamGroup && x.LocalTeamScore < x.VisitorTeamScore) ||
                                                                                   (x.IdVisitorTeam == tournamentPositionTable.IdTournamentTeamGroup && x.LocalTeamScore > x.VisitorTeamScore)).Count();
                tournamentPositionTableDto.GoalsScored = matchesPlayedByTeam.Where(x => x.IdLocalTeam == tournamentPositionTable.IdTournamentTeamGroup).Sum(x => (int)x.LocalTeamScore) +
                                                         matchesPlayedByTeam.Where(x => x.IdVisitorTeam == tournamentPositionTable.IdTournamentTeamGroup).Sum(x => (int)x.VisitorTeamScore);
                tournamentPositionTableDto.GoalsReceived = matchesPlayedByTeam.Where(x => x.IdLocalTeam == tournamentPositionTable.IdTournamentTeamGroup).Sum(x => (int)x.VisitorTeamScore) +
                                                           matchesPlayedByTeam.Where(x => x.IdVisitorTeam == tournamentPositionTable.IdTournamentTeamGroup).Sum(x => (int)x.LocalTeamScore);
                tournamentPositionTableDto.GoalsDifference = tournamentPositionTableDto.GoalsScored - tournamentPositionTableDto.GoalsReceived;
                tournamentPositionTableDto.Points          = (tournamentPositionTableDto.WonMatches * 3) + tournamentPositionTableDto.TiedMatches;

                tournamentPositionTablesToReturn.Add(tournamentPositionTableDto);
            }

            tournamentPositionTablesToReturn = tournamentPositionTablesToReturn.OrderByDescending(x => x.Points).ThenByDescending(x => x.GoalsDifference).ThenByDescending(x => x.GoalsScored).ThenBy(x => x.GoalsReceived).ToList();

            int count = 1;

            foreach (var tournamentPosition in tournamentPositionTablesToReturn)
            {
                tournamentPosition.Position = count;
                count++;
            }

            return(tournamentPositionTablesToReturn);
        }
Ejemplo n.º 4
0
        public bool UpdateTournamentPostionTable(TournamentPositionTableDto tournamentPositionTableDto)
        {
            TournamentPositionTableRepository tournamentPostionTableRepository = new TournamentPositionTableRepository();

            return(tournamentPostionTableRepository.UpdateTournamentPositionTable(tournamentPositionTableDto));
        }