public ActionResult <GolfRound> CreateGolfRound(GolfRound round) { GolfRound createdRound = golfRoundDAO.CreateGolfRound(round); // Make call to playerdAO for handicap calculation // Return handicap with an OK 200 /* * use playerId from createdRound to do another call to DB to get rounds * for that playerId. Then make pass that list of rounds into util method to * calculate handicap, then add handicap into db and return to front end * in util the class should be a static class */ if (createdRound == null) { return(BadRequest()); } List <GolfRound> rounds = golfRoundDAO.GetGolfRoundsByPlayerId(createdRound.PlayerId); List <double> scoreDifferentials = HandicapCalculator.CalculateScoreDifferentials(rounds); double handicap = HandicapCalculator.CalculateHandicap(scoreDifferentials); playerDAO.UpdateHandicap(handicap, createdRound.PlayerId); return(CreatedAtRoute("round", new { id = createdRound.GolfRoundId }, createdRound)); }
public void HandicapIsFive() { var calc = new HandicapCalculator(); var handicap = 60; var gameType = (int)GameType.Nineball; var expected = 4; var actual = calc.Calculate(handicap, gameType); actual.Should().Be(expected); }
public JsonResult UpdateScore(ScoresModel scoreToUpdate) { SqlTool sql = new SqlTool(); HandicapCalculator handicap = new HandicapCalculator(); decimal adjustedScore = handicap.AdjustScore(scoreToUpdate.score, scoreToUpdate.courseid); string updateScoreQuery = @"Update scores set Score = " + scoreToUpdate.score + ",adjustedscore = " + adjustedScore + " where id = " + scoreToUpdate.id; sql.runQuery(updateScoreQuery); return(Json(null, JsonRequestBehavior.AllowGet)); }
public JsonResult AddScore(ScoresModel newScore) { SqlTool sqltool = new SqlTool(); HandicapCalculator handicap = new HandicapCalculator(); //populate Course Model decimal adjustedScore = handicap.AdjustScore(newScore.score, newScore.courseid); string newScoreInsert = String.Format(@"INSERT INTO Scores(userid,courseid,score,dateplayed,adjustedscore) SELECT {0},{1},{2},'{3}',{4}", Session["id"], newScore.courseid, newScore.score, newScore.dateplayed.ToShortDateString(), adjustedScore); sqltool.runQuery(newScoreInsert); return(Json(newScore, JsonRequestBehavior.AllowGet)); }
public void StraightPoolMaxIs75HandicapIs100() { var config = new HandicapConfiguration(); config.StraigntPoolMax = 75; var mockConfigservice = new Mock <IHandicapConfigurationService>(); mockConfigservice.Setup(svc => svc.Get(It.IsAny <string>())).Returns( Task.FromResult(config) ); var calc = new HandicapCalculator(); var handicap = 90; var actual = calc.Calculate(handicap, config.StraigntPoolMax); actual.Should().Be(8); }