private async Task <Boolean> RecalculateHandicap(Handicap handicap) { IEnumerable <Handicap> allHandicaps = _handicapAccessLayer.GetOrderedHandicaps(handicap.PlayerId); var handicapsList = allHandicaps.Take(19).ToList(); handicapsList.Add(handicap); handicapsList = handicapsList.OrderBy(h => h.Value).ToList(); int roundsPlayed = handicapsList.Count(); Decimal newHandicap; if (roundsPlayed >= 19) { newHandicap = handicapsList.Take(8).Sum(h => h.Value) / 8; } else if (roundsPlayed >= 17) { newHandicap = handicapsList.Take(7).Sum(h => h.Value) / 7; } else if (roundsPlayed >= 15) { newHandicap = handicapsList.Take(6).Sum(h => h.Value) / 6; } else if (roundsPlayed >= 13) { newHandicap = handicapsList.Take(5).Sum(h => h.Value) / 5; } else if (roundsPlayed >= 11) { newHandicap = handicapsList.Take(4).Sum(h => h.Value) / 4; } else if (roundsPlayed >= 9) { newHandicap = handicapsList.Take(3).Sum(h => h.Value) / 3; } else if (roundsPlayed >= 7) { newHandicap = handicapsList.Take(2).Sum(h => h.Value) / 2; } else { newHandicap = handicapsList.Take(1).Sum(h => h.Value) / 1; } handicap.CurrentHandicap = newHandicap; await AddHandicap(handicap); return(await Edit(handicap.PlayerId, newHandicap)); }
public IActionResult GetOrderedHandicaps(Guid PlayerId) { return(Ok(_handicapAccessLayer.GetOrderedHandicaps(PlayerId))); }