コード例 #1
0
        public IActionResult Highscore(string puzzleName)
        {
            var mapper = new PuzzleMapper();
            PuzzleHighscoreViewModel vm;
            int puzzleId = -1;

            using (_context) {
                PuzzleDto puzzle = _context.Puzzles.First(x => x.Name == puzzleName);
                vm = new PuzzleHighscoreViewModel()
                {
                    Name = puzzle.Name, Highscores = new List <HighscoreViewModel>()
                };
                puzzleId = (int)puzzle.Id;
            }

            PuzzleReply reply = _hiscoreClient.GetPuzzleHighscore(new PuzzleRequest()
            {
                PuzzleId = puzzleId
            });

            foreach (PuzzleHighscore item in reply.Highscores.OrderBy(x => x.SecondsToComplete))
            {
                vm.Highscores.Add(new HighscoreViewModel {
                    PlayerName        = item.AttemptName,
                    SecondsToComplete = item.SecondsToComplete
                });
            }

            return(View(vm));
        }
コード例 #2
0
        public IActionResult Index()
        {
            var mapper = new PuzzleMapper();

            using (_context) {
                IEnumerable <PuzzleDto>       models = _context.Puzzles.OrderBy(x => x.Difficulty).ToList();
                IEnumerable <PuzzleViewModel> vm     = mapper.Map(models);
                return(View(vm));
            }
        }
コード例 #3
0
        public IActionResult Create(PuzzleViewModel vm)
        {
            var       mapper = new PuzzleMapper();
            PuzzleDto entity = mapper.Map(vm);

            using (_context) {
                _context.Puzzles.Add(entity);
                _context.SaveChanges();
            }
            return(RedirectToAction("index"));
        }
コード例 #4
0
        public void MapPuzzleToPuzzleEntity()
        {
            var puzzle = PuzzleFactory.GetPuzzle(Core.Enums.Difficulty.Medium);

            Assert.IsInstanceOfType(puzzle, typeof(MediumPuzzle));
            puzzle.CreatePuzzle();
            Assert.IsNotNull(puzzle.PuzzleArray);
            var dataMapper   = new PuzzleMapper();
            var puzzleEntity = dataMapper.MapPuzzleToPuzzleEntity(puzzle);

            Assert.AreEqual(puzzle.Id, puzzleEntity.Id);
        }
コード例 #5
0
        public void ShouldStorePuzzleEntityMappedFromPuzzle()
        {
            using (var context = new GameContext())
            {
                var puzzle = PuzzleFactory.GetPuzzle(Core.Enums.Difficulty.Medium);
                Assert.IsInstanceOfType(puzzle, typeof(MediumPuzzle));

                puzzle.CreatePuzzle();
                Assert.IsNotNull(puzzle.PuzzleArray);

                var dataMapper   = new PuzzleMapper();
                var puzzleEntity = dataMapper.MapPuzzleToPuzzleEntity(puzzle);
                puzzleEntity.Name = "test save";
                Assert.AreEqual(puzzle.Id, puzzleEntity.Id);

                context.PuzzleEntities.Add(puzzleEntity);
                context.SaveChanges();
            }
        }
コード例 #6
0
ファイル: GameRepository.cs プロジェクト: dcmoods/SudokuGame
        private PuzzleMapper _mapper; //PuzzleMapper object used for mapping data before/after persistence.

        public GameRepository(PuzzleMapper mappingFactory)
        {
            _mapper = mappingFactory;
        }