public async Task <ActionResult> UpdateGame(int gameId, [FromBody] GameBattleDto game) { var dbGame = _mapper.Map <GameBattle>(game); var updated = await _gameRepository.UpdateAsync(dbGame, gameId); if (updated == null) { return(NotFound()); } return(CreatedAtRoute("GetMap", new { gameMapId = updated.GameMapId }, updated)); }
public async Task <ActionResult> CreateGame(GameBattleDto game) { var gameEntity = _mapper.Map <GameBattle>(game); var blueTank = await _tankModelRepository.GetById(gameEntity.BlueTankModelId); if (blueTank == null) { return(NotFound("Blue Tank not in database")); } var redTank = await _tankModelRepository.GetById(gameEntity.RedTankModelId); if (redTank == null) { return(NotFound("Red Tank not in database")); } var gameMap = await _gameMapRepository.GetById(gameEntity.GameMapId); if (gameMap == null) { return(NotFound("Map is not in database")); } gameEntity.IsActive = true; gameEntity.CreatedTime = DateTime.Now; var newGame = await _gameRepository.Add(gameEntity); if (newGame == null) { return(BadRequest("Unable to insert game battle")); } //_unitOfWork.SaveChanges(); return(CreatedAtRoute("GetGame", new { gameId = newGame.GameBattleId }, newGame)); }