示例#1
0
 // analyse points and goals and set the position for each team
 private void CalculatePosition()
 {
     try {
         //get the Team with most points, then with best GoalRate
         var sortedList             = _soccerResultTableList.OrderByDescending(item => item.Points).ThenByDescending(item => item.GoalRate);
         var position               = 1;
         SoccerResultsItem lastItem = null;
         foreach (var resultTableItem in sortedList)
         {
             if (lastItem != null &&
                 resultTableItem.GoalRate == lastItem.GoalRate &&
                 resultTableItem.Points == lastItem.Points)
             {
                 //Equality of Points and GoalRate => SamePosition
                 position = lastItem.Position;
             }
             resultTableItem.Position = position;
             position++;
             lastItem = resultTableItem;
         }
         _soccerResultTableList = sortedList.ToList();
     }
     catch (Exception ex)
     {
         throw new Exception("Beim Berechnen der Ergebnisstabelle ist ein Fehler aufgetreten." +
                             Environment.NewLine + " Fehlercode: " + ex.Message);
     }
 }
示例#2
0
        //parse result Data and set points and goalRate for each Team
        public bool ParseResults(List <SoccerResultsData> soccerResultDataList)
        {
            try {
                bool resultVal         = true;
                var  soccerResultTable = new SoccerResultsItem();

                foreach (var soccerResultData in _soccerResultDataList)
                {
                    var diff = soccerResultData.NumberOfGoalsA - soccerResultData.NumberOfGoalsB;
                    diff = (diff == 0) ? 0 : (diff < 0) ? -1 : 1;
                    switch (diff)
                    {
                    //unentschieden
                    case  0:
                        SetPointsAnGoalRateToTeam(soccerResultData.TeamA, equalPoint, soccerResultData.NumberOfGoalsA);
                        SetPointsAnGoalRateToTeam(soccerResultData.TeamB, equalPoint, soccerResultData.NumberOfGoalsB);
                        break;

                    //Win TeamB
                    case -1:
                        SetPointsAnGoalRateToTeam(soccerResultData.TeamB, winningPoints, soccerResultData.NumberOfGoalsB);
                        SetPointsAnGoalRateToTeam(soccerResultData.TeamA, loosingPoint, soccerResultData.NumberOfGoalsA);
                        break;

                    //Win TeamA
                    case 1:
                        SetPointsAnGoalRateToTeam(soccerResultData.TeamA, winningPoints, soccerResultData.NumberOfGoalsA);
                        SetPointsAnGoalRateToTeam(soccerResultData.TeamB, loosingPoint, soccerResultData.NumberOfGoalsB);
                        break;
                    }
                }

                CalculatePosition();

                return(resultVal);
            }
            catch (Exception ex)
            {
                throw new Exception("Beim Analysieren der Ergebnisse ist ein Fehler aufgetreten. Bitte prüfen Sie die Eingabedatei." +
                                    Environment.NewLine + " Fehlercode: " + ex.Message);
            }
        }