/// <summary> /// Assign club points from the athlete results. Update the model. /// </summary> /// <param name="resultsTable">reference to current results table</param> /// <param name="currentDate">date of current event</param> /// <param name="scoringPositions">number of scoring positions</param> private void AssignMobTrophyPoints( EventResults resultsTable, DateType currentDate, List <MobTrophyPoints> mobTrophyPointsWorking) { if (!this.resultsConfiguration.ResultsConfigurationDetails.UseTeams) { return; } resultsTable.OrderByFinishingTime(); foreach (ResultsTableEntry result in resultsTable.Entries) { if (result.Club == string.Empty) { continue; } MobTrophyPoints club = mobTrophyPointsWorking.Find(clubName => clubName.ClubName.CompareTo(result.Club) == 0); if (club != null) { club.AddNewResult( result.Points.PositionPoints, result.FirstTimer, result.SB); } } this.SaveMobTrophyPointsToModel( mobTrophyPointsWorking, currentDate); }
/// <summary> /// Add new points to the view model /// </summary> /// <param name="newPoints">points to add</param> public void AddPoints(PointsType newPoints) { MobTrophyPoints.Add(newPoints); }
/// ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- /// <name>SaveAthleteSeasonData</name> /// <date>30/03/15</date> /// <summary> /// Reads the athlete season details xml from file and decodes it. /// </summary> /// <param name="fileName">name of xml file</param> /// <returns>decoded athlete's details</returns> /// ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- public List <IClubSeasonDetails> LoadClubSeasonData(string fileName) { List <IClubSeasonDetails> seasonDetails = new List <IClubSeasonDetails>(); try { XDocument reader = XDocument.Load(fileName); XElement rootElement = reader.Root; var clubList = from Club in rootElement.Elements(c_clubElement) select new { name = (string)Club.Attribute(nameAttribute), mobTrophyPoints = from MobTrophyPoints in Club.Elements(MobTrophyPointsElement) select new { point = from Point in MobTrophyPoints.Elements(c_eventPointsElement) select new { finishing = (int)Point.Attribute(finishingPointsAttribute), position = (int)Point.Attribute(positionPointsAttribute), best = (int)Point.Attribute(bestPointsAttribute), date = (string)Point.Attribute(eventDateAttribute) } }, teamTrophyPoints = from TeamTrophyPoints in Club.Elements(TeamTrophyPointsElement) select new { events = from TeamTrophyEvent in TeamTrophyPoints.Elements(EventElement) select new { size = (int)TeamTrophyEvent.Attribute(TeamTrophyTeamSizeAttribute), virtualPoint = (int)TeamTrophyEvent.Attribute(TeamTrophyVirtualAthletePointAttribute), date = (string)TeamTrophyEvent.Attribute(TeamTrophyEventDateAttribute), score = (int)TeamTrophyEvent.Attribute(TeamTrophyScoreAttribute), points = from Point in TeamTrophyEvent.Elements(c_eventPointsElement) select new { value = (int)Point.Attribute(TeamTrophyPointAttribute), key = (int)Point.Attribute(AthleteKeyAttribute) } } } }; foreach (var club in clubList) { ClubSeasonDetails clubDetails = new ClubSeasonDetails(club.name); foreach (var points in club.mobTrophyPoints) { foreach (var point in points.point) { DateType date = new DateType( point.date); CommonPoints readPoints = new CommonPoints( point.finishing, point.position, point.best, date); clubDetails.MobTrophy.AddNewEvent(readPoints); // TODO, should probably check that there are the correct number read from the xml file. // i.e. there is one for each event in the currently loaded season. } } foreach (var teamTrophyPoints in club.teamTrophyPoints) { foreach (var teamTrophyEvent in teamTrophyPoints.events) { List <ICommonTeamTrophyPoints> pointsList = new List <ICommonTeamTrophyPoints>(); DateType date = new DateType( teamTrophyEvent.date); foreach (var point in teamTrophyEvent.points) { CommonTeamTrophyPoints readPoints = new CommonTeamTrophyPoints( point.value, string.Empty, point.key, true, date); pointsList.Add(readPoints); } ITeamTrophyEvent readEvent = new TeamTrophyEvent( date, pointsList, teamTrophyEvent.size, teamTrophyEvent.score); readEvent.Complete( teamTrophyEvent.size, teamTrophyEvent.virtualPoint); clubDetails.TeamTrophy.AddEvent(readEvent); } } seasonDetails.Add(clubDetails); } } catch (Exception ex) { this.logger.WriteLog("Error reading athlete data: " + ex.ToString()); seasonDetails = new List <IClubSeasonDetails>(); } return(seasonDetails); }