public ActionResult Create() { var viewModel = new CreateGameViewModel { Courses = courseRepository.GetAll(), OtherUsers = userRepository.GetAll() .Where(x => x.UserName != User.Identity.Name).ToList() }; return View(viewModel); }
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); }