public async Task <ActionResult> NewGame(GameInputViewModel game) { if (!ModelState.IsValid) { return(View(game)); } var gameBll = _mapperWeb.Map <GameBll>(game); try { await _gameService.AddAsync(gameBll); } catch (ValidationException ex) { ModelState.AddModelError("", ex.Message); return(View(game)); } catch (AccessException ex) { ModelState.AddModelError("", ex.Message); return(View(game)); } catch (Exception) { ModelState.AddModelError("", "Bad request"); return(View(game)); } // Success!!! return(RedirectToAction("Index")); }
public async Task <IActionResult> Post([FromBody] BLGame game) { if (game == null || game.PublisherId <= 0 || game.Name.Length == 0) { return(BadRequest("Wrong game model")); } await _gameService.AddAsync(game); return(Created("api/games/", game)); }
public async Task <IActionResult> PostGame(GameViewModel gameViewModel) { if (gameViewModel is null) { throw new System.ArgumentNullException(nameof(gameViewModel)); } var gameDto = _mapper.Map <GameDto>(gameViewModel); var result = await _gameService.AddAsync(gameDto); return(Ok(result)); }
protected override async Task <GetGameDto> ExecuteAsync(CreateGameCommand request, CancellationToken ct) { var game = await _service.AddAsync(_mapper.Map <AddGameDto>(request), ct); var message = _mapper.Map <GameCreatedMessage>(game); _mapper.Map(game.GameDetails, message); await _serviceBusClient.PublishGameCreatedAsync(message); return(game); }
public async Task <ActionResult <bool> > Post([FromBody] List <GameDto> items) { try { await service.AddAsync(items); return(Ok(true)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
private async Task <Game> CreateGameIfNotExistsAsync() { var game = new Game { Id = Guid.NewGuid() }; var(count, games) = await m_gameService.SearchAsync(new Pagination(), new SimpleFilter <Game>()); if (count == 0) { await m_gameService.AddAsync(game); } else { game = games.First(t => t.State.Equals(GameState.Pending)); } return(game); }
protected override async Task <GetGameDto> ExecuteAsync(CreateGameCommand request, CancellationToken ct) { AddGameDto accountDto = _mapper.Map <AddGameDto>(request); return(await _gameService.AddAsync(accountDto, ct)); }
public async Task <IActionResult> PostGame([FromBody] Game game) { return(ApiOk(await GameService.AddAsync(game))); }
public async Task <IActionResult> Edit(GameEditViewModel vm) { if (!ModelState.IsValid) { return(View(vm)); } if (vm.Id.HasValue) { var game = await _gameService.GetByIdAsync(vm.Id.Value); if (game == null) { return(StatusCode((int)HttpStatusCode.NotFound)); } game.Name = vm.Name; game.Status = vm.Status; game.HasSite = vm.HasSite; game.GameKey = vm.GameKey; game.LinkEntryTypes = vm.LinkEntryTypes; game.StringEntryTypes = vm.StringEntryTypes; game.ValueEntryTypes = vm.ValueEntryTypes; game.TagEntryTypes = vm.TagEntryTypes; if (vm.GameLogo != null) { if (game.GameLogo != null) { game.GameLogo.File = vm.GameLogo.Getbytes(); game.GameLogo.LastModified = DateTime.UtcNow; } else { game.GameLogo = new ImageDto() { File = vm.GameLogo.Getbytes() }; } } await _gameService.EditAsync(game); } else { var game = new GameDto() { Name = vm.Name, HasSite = vm.HasSite, GameKey = vm.GameKey, Status = vm.Status, GameLogo = vm.GameLogo != null ? new ImageDto() { File = vm.GameLogo.Getbytes() } : null, StringEntryTypes = vm.StringEntryTypes, ValueEntryTypes = vm.ValueEntryTypes, LinkEntryTypes = vm.LinkEntryTypes, TagEntryTypes = vm.TagEntryTypes }; await _gameService.AddAsync(game); } return(RedirectToAction("Index", "Game")); }
public async void CreateGames() { Random r = new Random(); var numberGames = 0; Console.WriteLine("Creating 100 games"); Console.WriteLine(); Console.WriteLine(); while (numberGames < 1) { numberGames++; Console.WriteLine($"Start the {numberGames} game ..."); Console.WriteLine(); await CreatePlayer(1); await CreatePlayer(2); Game game; try { game = await _gameService.AddAsync(new Game { EndGame = false, PlayerGameWinnerName = "" }); Console.WriteLine($"Game {game.Id} Created Succefully"); Console.WriteLine(); } catch (Exception ex) { Console.WriteLine($"Error: {ex}"); continue; } var numberRound = 1; var player1 = await _playerService.GetPlayerByNumber(1); var player2 = await _playerService.GetPlayerByNumber(2); while (true) { Console.WriteLine($"Round {numberRound}"); numberRound++; Round round; try { var player1Move = (Move)r.Next(1, 4); round = await _roundService.AddAsync(new Round { Player1Move = player1Move, GameId = game.Id }); Console.WriteLine($"{player1.PlayerName} played {player1Move}"); Console.WriteLine(); } catch (Exception ex) { Console.WriteLine($"Error with Player 1 move: {ex}"); break; } try { Console.WriteLine(round.Id); var player2Move = (Move)r.Next(1, 4); var rnd = await _roundService.SingleOrDefaultAsync(round.Id); if (rnd != null) { game = await _roundService.CompleteRound(rnd, player2Move); } Console.WriteLine($"{player2.PlayerName} played {player2Move}"); Console.WriteLine(); } catch (Exception ex) { Console.WriteLine($"Error with Player 2 move: {ex}"); break; } if (game.EndGame) { Console.WriteLine($"Game {numberGames} winner is {game.PlayerGameWinnerName}"); Console.WriteLine(); break; } } } Console.WriteLine("Statics for players"); foreach (var name in PlayerNames) { try { var result = await _gameService.Statistics(name); Console.WriteLine($"{name} won {result.Count} games"); Console.WriteLine(); } catch (Exception ex) { Console.WriteLine($"Error: {ex}"); continue; } } Console.WriteLine("Test Finish"); }
protected override async Task ExecuteAsync(CreateGameCommand request, CancellationToken ct) { AddGameDto game = _mapper.Map <AddGameDto>(request); await _gameService.AddAsync(game, ct); }