public IHttpActionResult CreateGame(CreateGameBindingModel model) { this._currentUserId = this._userIdProvider.GetUserId(); var theUser = this._data.Users.FirstOrDefault(u => u.Id == this._currentUserId); var newGame = new Game() { Name = model.Name, FirstPlayerId = this._currentUserId, CreatedTime = DateTime.Now, State = GameState.WaitingForSecondPlayer }; this._data.Games.Add(newGame); this._data.SaveChanges(); JoinGameViewModel gameViewModel = new JoinGameViewModel() { Id = newGame.Id, Name = newGame.Name, FirstPlayerName = theUser.UserName, GameState = GameState.WaitingForSecondPlayer.ToString(), Field = newGame.Field }; return(this.Ok(gameViewModel)); }
public IActionResult Create(CreateGameBindingModel input) { if (!ModelState.IsValid) { return(View(input)); } var createdGame = this.gameService.Create(input, this.User.Identity.GetUserId()); return(RedirectToAction(nameof(Play), new { Id = createdGame.Id })); }
public ActionResult Create(string id, [Bind(Include = "Start, End, IsWeekly")] CreateGameBindingModel bindingModel) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } if (ModelState.IsValid) { this._service.CreateGame(id, bindingModel); return(RedirectToAction("Calendar")); } return(View(bindingModel)); }
public void CreateGame(string id, CreateGameBindingModel bindingModel) { Game game = Mapper.Map<CreateGameBindingModel, Game>(bindingModel); game.Id = Guid.NewGuid().ToString(); Group group = this.Context.Groups.Find(id); game.Group = group; game.IsPattern = false; if (game.IsWeekly) { game.IsPattern = true; PopulateWeeklyGames(game, group); } this.Context.Games.Add(game); this.Context.SaveChanges(); }
/// <inheritdoc /> public GameStatusViewModel Create(CreateGameBindingModel input, string creatorUserId) { if (string.IsNullOrWhiteSpace(creatorUserId)) { throw new ValidationException(ErrorMessagesConstants.USERID_IS_NULL); } var game = new Game() { Name = input.Name, Visibility = input.Visibility, HashedPassword = input.Password, CreatorUserId = creatorUserId, State = GameState.WaitingForASecondPlayer }; context.Games.Add(game); context.SaveChanges(); return(game.ToGameStatus()); }