Ejemplo n.º 1
0
        public virtual BowlingLine RecordBowlingLine(BowlingLine bowlingLine)
        {
            _bowlingLineRepository.Persist(bowlingLine);

            return bowlingLine;

        }
Ejemplo n.º 2
0
        /// <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;

            }
        }
Ejemplo n.º 3
0
        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>();
                


        }
Ejemplo n.º 4
0
 public void Persist(BowlingLine bowlingLine)
 {
 
 }