示例#1
0
        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));
        }
示例#2
0
        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;
            }
        }
示例#3
0
        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);
        }
示例#4
0
        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);
        }
示例#5
0
        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));
        }
示例#6
0
        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());
        }
示例#7
0
 public IEnumerable <League> Get()
 {
     return(DataFileService.GetDataFile <League>(DataFileType.Leagues));
 }
示例#8
0
 public IEnumerable <FishingMatch> Get()
 {
     return(DataFileService.GetDataFile <FishingMatch>(DataFileType.Matches));
 }
示例#9
0
 public IEnumerable <Angler> Get()
 {
     return(DataFileService.GetDataFile <Angler>(DataFileType.Anglers));
 }