//[Authorize] public ActionResult Create( CreateGameRequestViewModel viewModel //[Bind(Include = "Id,SgfString,BoardSizeId,BlackPlayerId,WhitePlayerId,BlackPlayerRankId,WhitePlayerRankId,CreatorId,CreationTimestamp,StartTimestamp,LastPlayedTimestamp,EndTimestamp,Moves,CompensationPoints,HandicapStones,Turn,GameResultId,TournamentId,Type")] Game game ) { if (ModelState.IsValid) { GameRequest gameRequest = db.GameRequests.Create(); gameRequest.Author = CurrentUser; gameRequest.CreationTimestamp = DateTime.Now; gameRequest.Type = GameType.CORRESPONDENCE; gameRequest.HandicapStones = 0; gameRequest.CompensationPoints = 6.5; gameRequest.RuleSet = db.RuleSets.Find(0); gameRequest.BoardSize = db.BoardSizes.Find(viewModel.BoardSizeId); gameRequest.IsOpen = true; gameRequest.HandicapStonesPlacement = HandicapStonesPlacement.FIXED; gameRequest.ColorOfAuthor = Color.BLACK; db.GameRequests.Add(gameRequest); db.SaveChanges(); return(RedirectToAction("MyRequests")); } return(View(viewModel)); }
/// <summary> /// Создать игру /// </summary> /// <param name="createGameRequest">Описание создаваемой игры</param> public async Task CreateGame(CreateGameRequestViewModel createGameRequest) { var game = gameService.FindById(createGameRequest.ScenarioId); if (game == null) { await Clients.Caller.SendAsync(nameof(CreateGame), RequestResult.Err("Invalid scenario id")); return; } var userName = (string)Context.Items[CLIENT_USERNAME_FIELD]; var gameSession = gameSessionService.Create(game, userName, createGameRequest.Name); await Clients.Caller.SendAsync(nameof(CreateGame), RequestResult.Ok(gameSession.Id)); await Clients.All.SendAsync("GameCreated", RequestResult.Ok(gameSession)); }