Exemple #1
0
        public IEnumerable <HoleScore> Post(int scoreId, [FromBody] List <HoleScore> holeScores)
        {
            Console.Out.WriteLine("Controller=HoleScoresController,Method=Post,HoleCount={0}", holeScores.Count);
            var golfScores = repository.ReadScores();
            var golfScore  = golfScores.FirstOrDefault(x => x.Id == scoreId);

            golfScore.HoleScores = holeScores;
            repository.SaveScores(golfScores);
            return(golfScore.HoleScores);
        }
        public int Post([FromBody] GolfScore newScore)
        {
            Console.Out.WriteLine("Controller=ScoresController,Method=Post,FriendlyMessage=String received -> '{0}'", newScore);
            var newId = golfScores.Count + 2;

            try
            {
                Console.Out.WriteLine("Controller=ScoresController,Method=Post,FriendlyMessage=newScore.Id -> {0}", newScore.Id);
                newScore.Id = newId;
                golfScores.Add(newScore);
                Console.Out.WriteLine("Controller=ScoresController,Method=Post,FriendlyMessage='Items in golfScores -> {0}'", golfScores.Count);
                repository.SaveScores(golfScores);
            }
            catch (Exception e)
            {
                Console.Out.WriteLine("Controller=ScoresController,Method=Post,Exception={0}", e.Message);
                // newScore = ManufactureScore();
                // golfScores.Add(newScore);
            }

            return(newScore == null ? -1 : newScore.Id);
        }