public virtual BowlingLine RecordBowlingLine(BowlingLine bowlingLine) { _bowlingLineRepository.Persist(bowlingLine); return bowlingLine; }
/// <summary> /// accepts a bowling line with a collection of players with scores in string format and uses the parser to /// get the frame scores and then the injected calculator to add them up. /// </summary> /// <param name="bowlingLine"></param> /// <returns></returns> public void CalculateScores(BowlingLine bowlingLine) { if (bowlingLine == null) { throw new TenpinBowlingException("Bowling Line cannot be null"); } if (bowlingLine.Players == null || !bowlingLine.Players.Any()) { throw new TenpinBowlingException("Bowling Line has no player scores"); } foreach(var player in bowlingLine.Players) { var scores = _bowlingScoreParser.ParseScores(player.RecordedScore).ToList(); var frames = _bowlingFrameBuilder.BuildScores(scores).ToList(); ValidateFrames(frames); var totalScore = _scoreCalculator.CalculateTotalScore(frames); player.TotalScore = totalScore; } }
public static void CreateMappings() { Mapper.CreateMap<AddBowlingLineModel, BowlingLine>() .ConstructUsing(src => { var bowlingLine = new BowlingLine(Mapper.Map<List<BowlingLineScore>>(src.BowlingLineScores)); return bowlingLine; }); Mapper.CreateMap<BowlingLineScoreModel, BowlingLineScore>() .ConstructUsing(src => { var bowlingLineScore = new BowlingLineScore(src.Name, src.Scores); return bowlingLineScore; }); Mapper.CreateMap<BowlingLine, BowlingLineSummaryModel>() .ConstructUsing(src => { var summary = new BowlingLineSummaryModel {BowlerSummaries = new List<BowlerSummaryModel>()}; foreach (var player in src.Players) { summary.BowlerSummaries.Add(Mapper.Map<BowlerSummaryModel>(player)); } return summary; }); Mapper.CreateMap<Bowler, BowlerSummaryModel>(); }
public void Persist(BowlingLine bowlingLine) { }