private GameDetails GetGameToAddFromSearch(List <SearchBoardGameResult> searchResult) { var gamesToAdd = searchResult.Select( searchBoardGameResult => _boardGameGeekApiClient.GetGameDetails(searchBoardGameResult.BoardGameId)) .Where(gameDetails => gameDetails != null) .ToList(); var gameToAdd = gamesToAdd.Where(g => g.Thumbnail != null) .OrderByDescending(g => g.BGGRating) .FirstOrDefault(); return(gameToAdd); }
public int?CreateBoardGameGeekGameDefinition(int boardGameGeekGameDefinitionId, ApplicationUser currentUser) { BoardGameGeekGameDefinition existingRecord = null; try { existingRecord = dataContext.FindById <BoardGameGeekGameDefinition>(boardGameGeekGameDefinitionId); if (existingRecord != null) { return(boardGameGeekGameDefinitionId); } } catch (EntityDoesNotExistException) { //this is OK, just means we need to create a new one }catch (Exception) { throw; } var gameDetails = boardGameGeekApiClient.GetGameDetails(boardGameGeekGameDefinitionId); if (gameDetails == null) { return(null); } var newRecord = new BoardGameGeekGameDefinition { Id = boardGameGeekGameDefinitionId, Name = gameDetails.Name, Thumbnail = gameDetails.Thumbnail }; dataContext.Save(newRecord, currentUser); return(boardGameGeekGameDefinitionId); }
public BoardGameGeekGameDefinition CreateBoardGameGeekGameDefinition(int boardGameGeekGameDefinitionId, ApplicationUser currentUser) { try { var existingRecord = _dataContext.FindById <BoardGameGeekGameDefinition>(boardGameGeekGameDefinitionId); if (existingRecord != null) { return(existingRecord); } } catch (EntityDoesNotExistException) { //this is OK, just means we need to create a new one } var gameDetails = _boardGameGeekApiClient.GetGameDetails(boardGameGeekGameDefinitionId); if (gameDetails == null) { return(null); } var newRecord = new BoardGameGeekGameDefinition { Id = boardGameGeekGameDefinitionId, Name = gameDetails.Name, Thumbnail = gameDetails.Thumbnail, Image = gameDetails.Image, MaxPlayers = gameDetails.MaxPlayers, MinPlayers = gameDetails.MinPlayers, MaxPlayTime = gameDetails.MaxPlayTime, MinPlayTime = gameDetails.MinPlayTime, AverageWeight = gameDetails.AverageWeight, Description = gameDetails.Description, YearPublished = gameDetails.YearPublished, IsExpansion = gameDetails.IsExpansion, Rank = gameDetails.Rank }; _dataContext.Save(newRecord, currentUser); // Save categories to BGG definition foreach (var category in gameDetails.Categories) { var existentCategory = _dataContext.GetQueryable <BoardGameGeekGameCategory>().FirstOrDefault(c => c.BoardGameGeekGameCategoryId == category.Id); if (existentCategory == null) { existentCategory = new BoardGameGeekGameCategory() { BoardGameGeekGameCategoryId = category.Id, CategoryName = category.Category }; } newRecord.Categories.Add(existentCategory); } foreach (var mechanic in gameDetails.Mechanics) { var existentMechanic = _dataContext.GetQueryable <BoardGameGeekGameMechanic>().FirstOrDefault(c => c.BoardGameGeekGameMechanicId == mechanic.Id); if (existentMechanic == null) { existentMechanic = new BoardGameGeekGameMechanic() { BoardGameGeekGameMechanicId = mechanic.Id, MechanicName = mechanic.Mechanic }; } newRecord.Mechanics.Add(existentMechanic); } return(newRecord); }