public async Task AddAsync(GameBll entity) { if (!IsValidGame(entity)) { throw new ValidationException($"The game is not valid"); } if (await GetGameByKeyAsync(entity.Key) != null) { throw new ValidationException($"The game with the key: {entity.Key} is already exist"); } var game = MapperBll.Map <Game>(entity); await ProjectGenresToDAlAsync(game.Genres, entity.Genres); await ProjectPlatformTypesToDAlAsync(game.PlatformTypes, entity.PlatformTypes); try { _gameRepository.Add(game); await Database.CommitAsync(); } catch (Exception ex) { throw new AccessException($"Can not add game {entity.Key} to database", "", ex); } }
public async Task UpdateAsync(GameBll entity) { if (!IsValidGame(entity)) { return; } var game = await GetGameByKeyAsync(entity.Key); if (game == null) { throw new ValidationException($"The game {entity.Key} is not exist"); } MapperBll.Map(entity, game); await ProjectGenresToDAlAsync(game.Genres, entity.Genres); await ProjectPlatformTypesToDAlAsync(game.PlatformTypes, entity.PlatformTypes); try { _gameRepository.Update(game); await Database.CommitAsync(); } catch (Exception ex) { throw new AccessException($"Can not add game {entity.Key} to database", "", ex); } }
public async Task <List <GameBll> > GetByPlatformTypeAsync(string platformType) { if (!IsValidKey(platformType)) { return(null); } var games = await GetGamesAsync(d => d.PlatformTypes.Any(t => t.Type.Equals(platformType))); return(MapperBll.Map <List <GameBll> >(games)); }
public async Task <List <GameBll> > GetByGenreAsync(string name) { if (!IsValidKey(name)) { return(null); } var games = await GetGamesAsync(d => d.Genres.Any(t => t.Name.Equals(name))); return(MapperBll.Map <List <GameBll> >(games)); }
public async Task <GameBll> GetDetailsByKeyAsync(string gamekey) { if (!IsValidKey(gamekey)) { return(null); } var game = await GetGameByKeyAsync(gamekey, "Genres, PlatformTypes"); return(MapperBll.Map <GameBll>(game)); }
public async Task UpdateAsync(CommentBll entity) { if (!IsValidComment(entity)) { return; } var comment = MapperBll.Map <Comment>(entity); try { _commentRepository.Add(comment); await Database.CommitAsync(); } catch (Exception ex) { throw new AccessException($"Can not add comment {entity.Name} to database", "", ex); } }
public async Task <List <CommentBll> > GetCommentsAsync(string gamekey) { if (gamekey == null) { throw new ValidationException("Invalid gamekey"); } IEnumerable <Comment> comments = null; try { comments = await _commentRepository.GetAsync(x => x.Game.Key.Equals(gamekey)); } catch (Exception ex) { throw new AccessException("Can't get the game from database", "", ex); } if (comments == null) { throw new ValidationException("The Game not found"); } return(MapperBll.Map <List <CommentBll> >(comments)); }
public async Task <List <GameBll> > GetAllAsync() { var games = await GetGamesAsync(); return(MapperBll.Map <List <GameBll> >(games)); }