public IHttpActionResult Post(int matchId, [FromBody] EntryToAdd entryToAdd) { List <FishingMatch> fishingMatches = DataFileService.GetDataFile <FishingMatch>(DataFileType.Matches).ToList(); FishingMatch fishingMatch = fishingMatches.SingleOrDefault(match => match.Id == matchId); if (fishingMatch == null) { return(NotFound()); } var matchEntry = new MatchEntry { AnglerName = entryToAdd.AnglerName, AnglerId = entryToAdd.AnglerId, Peg = entryToAdd.Peg, Weight = entryToAdd.Pounds + (entryToAdd.Ounces / OuncesInPound) }; fishingMatch.MatchEntries.Add(matchEntry); fishingMatch.CalculateMatchPoints(); DataFileService.WriteDataFile(DataFileType.Matches, fishingMatches); return(Created(string.Empty, entryToAdd)); }
public static void CalculateMatchPoints(this FishingMatch fishingMatch) { List <MatchEntry> sortedMatchEntries = fishingMatch.MatchEntries.OrderByDescending(matchEntry => matchEntry.Weight).ToList(); PositionToPointsMapping positionToPointsMapping = DataFileService.GetDataFile <PositionToPointsMapping>(DataFileType.PositionToPointsMapping) .SingleOrDefault(mapping => mapping.Id == fishingMatch.PositionToPointsMappingId); if (positionToPointsMapping == null) { throw new Exception("Position to points mapping not found"); } for (var index = 0; index < sortedMatchEntries.Count; index++) { sortedMatchEntries[index].Position = index + 1; if (Math.Abs(sortedMatchEntries[index].Weight) <= 0) { sortedMatchEntries[index].Points = positionToPointsMapping.DidNotWeighPoints; continue; } if (index > positionToPointsMapping.PositionToPoints.Count - 1) { sortedMatchEntries[index].Points = positionToPointsMapping.PositionToPoints.Last().Points; continue; } sortedMatchEntries[index].Points = positionToPointsMapping.PositionToPoints[index].Points; } }
public List <string> Get() { IEnumerable <FishingMatch> matches = DataFileService.GetDataFile <FishingMatch>(DataFileType.Matches); List <string> seasons = matches.GroupBy(match => match.Season) .Select(group => group.Key) .ToList(); seasons.Insert(0, "All"); return(seasons); }
public IEnumerable <Season> GetSeasons() { IEnumerable <FishingMatch> matches = DataFileService.GetDataFile <FishingMatch>(DataFileType.Matches); IEnumerable <Season> seasons = matches.GroupBy(match => new { match.SeasonId, match.Season }) .Select(group => new Season { Id = group.Key.SeasonId, Description = group.Key.Season }); return(seasons); }
public IHttpActionResult GetMatchEntries(int matchId) { FishingMatch fishingMatch = DataFileService.GetDataFile <FishingMatch>(DataFileType.Matches) .SingleOrDefault(match => match.Id == matchId); if (fishingMatch == null) { return(NotFound()); } return(Ok(fishingMatch.MatchEntries)); }
public List <ChampionshipAnglerDetails> Get([FromUri] int seasonId) { List <FishingMatch> matches = DataFileService.GetDataFile <FishingMatch>(DataFileType.Matches) .Where(match => match.SeasonId == seasonId) .ToList(); IEnumerable <string> anglerNames = matches.SelectMany(match => match.MatchEntries) .GroupBy(matchEntry => matchEntry.AnglerName) .Select(group => @group.Key); return((from anglerName in anglerNames let rounds = GetChampionshipRounds(matches, anglerName) select new ChampionshipAnglerDetails { Rounds = rounds, PointsTotal = rounds.Sum(matchEntry => matchEntry.Points), WeightTotal = rounds.Sum(matchEntry => matchEntry.Weight), Name = anglerName, MatchCount = rounds.Count(matchEntry => matchEntry.MatchFished) }).ToList()); }
public IEnumerable <League> Get() { return(DataFileService.GetDataFile <League>(DataFileType.Leagues)); }
public IEnumerable <FishingMatch> Get() { return(DataFileService.GetDataFile <FishingMatch>(DataFileType.Matches)); }
public IEnumerable <Angler> Get() { return(DataFileService.GetDataFile <Angler>(DataFileType.Anglers)); }