Ejemplo n.º 1
0
        public ActionResult Create()
        {
            var viewModel = new CreateGameViewModel
            {
                Courses = courseRepository.GetAll(),
                OtherUsers = userRepository.GetAll()
                .Where(x => x.UserName != User.Identity.Name).ToList()
            };

            return View(viewModel);
        }
Ejemplo n.º 2
0
        public ActionResult Create(CreateGameViewModel viewModel)
        {
            var game = new Game
            {
                CreatedDate = DateTime.Now,
                Course = courseRepository.Get(viewModel.SelectedCourseId)
            };
            game.AddPlayer(userRepository.GetByUserName(User.Identity.Name));
            foreach (var selectedOtherUser in viewModel.SelectedOtherUserNames)
            {
                game.AddPlayer(userRepository.GetByUserName(selectedOtherUser));
            }
            game.CreateRounds();

            if (ModelState.IsValid)
            {
                gameRepository.Create(game);
                gameRepository.Save();

                return RedirectToAction("Continue", new { id = game.Id });
            }

            return View(viewModel);
        }