public IActionResult Index(Guid CourseId)
        {
            try
            {
                var course = _courseAccessLayer.GetCourse(CourseId);
                var highestPossibleScore = course.Par + 50;
                var lowestPossibleScore  = course.Par - 10;
                var players = _playerAccessLayer.GetAllPlayers();
                var rounds  = _golfRoundAccessLayer.GetAllGolfRounds().Where(r => r.CourseId.Equals(CourseId));

                IList <Forecast> forecasts = new List <Forecast>();

                foreach (var player in players)
                {
                    var playerScores = _scoreAccessLayer.GetAllPlayerScores(player.Id);
                    IEnumerable <int> playerScoresForCourse = playerScores.Join(rounds,
                                                                                score => score.GolfRoundId,
                                                                                round => round.Id,
                                                                                (score, round) => score.Value);
                    if (playerScoresForCourse.Count() == 0)
                    {
                        playerScoresForCourse = playerScores.Select(s => s.Value);
                    }
                    var playerForecast = forecast(player, playerScoresForCourse, course, lowestPossibleScore, highestPossibleScore);
                    forecasts.Add(playerForecast);
                }

                return(Ok(forecasts));
            }
            catch
            {
                return(BadRequest());
            }
        }
Пример #2
0
        public IActionResult Details(Guid id)
        {
            var details = _courseAccessLayer.GetCourse(id);

            if (details != null)
            {
                return(Ok(details));
            }
            else
            {
                return(NotFound("Could not find course"));
            }
        }
Пример #3
0
        private async Task <Boolean> CalculateHandicap(DateTime date, Score score, Guid courseId)
        {
            Course   course   = _courseAccessLayer.GetCourse(courseId);
            Handicap handicap = new Handicap
            {
                Date     = date,
                PlayerId = score.PlayerId
            };

            int     holesMultiplier = course.Holes.Contains("-") ? 2 : 1;
            Decimal currentHandicap = _handicapAccessLayer.GetLatestHandicap(score.PlayerId).CurrentHandicap;

            decimal dailyHandicap = Math.Floor(currentHandicap * course.Slope / Decimal.Parse("113")
                                               + (course.ScratchRating - course.Par) * (decimal)(holesMultiplier * 0.93));

            handicap.Value = (36 - score.Value + dailyHandicap + course.Par - course.ScratchRating) *
                             (Decimal.Parse("113") / course.Slope);

            return(await RecalculateHandicap(handicap));
        }