public virtual async Task <List <IdentityUserLoginEntity> > GetUserLoginsAsync(long userId, CancellationToken cancellationToken) { using var da = _dbContext.GetNewAdapter(); var metaData = new LinqMetaData(da); var result = await(from login in metaData.IdentityUserLogin where login.UserId == userId select login).ExecuteAsync <EntityCollection <IdentityUserLoginEntity> >(cancellationToken); return(result.ToList()); }
public virtual async Task <List <CompletedMatchRow> > GetCompletedMatchesAsync(IPredicateExpression filter, CancellationToken cancellationToken) { using var da = _dbContext.GetNewAdapter(); return(await da.FetchQueryAsync <CompletedMatchRow>( new QueryFactory().CompletedMatch.Where(filter), cancellationToken)); }
public virtual async Task <IList <UserEntity> > GetTeamManagersAsync(long teamId, CancellationToken cancellationToken) { using var da = _dbContext.GetNewAdapter(); var metaData = new LinqMetaData(da); var result = await(from mot in metaData.ManagerOfTeam where mot.TeamId == teamId select mot.User).ToListAsync(cancellationToken); return(result); }
public virtual async Task <IList <IdentityUserClaimEntity> > GetUserClaimsAsync(long userId, CancellationToken cancellationToken) { using var da = _dbContext.GetNewAdapter(); var metaData = new LinqMetaData(da); var result = await(from uc in metaData.IdentityUserClaim where uc.UserId == userId select uc).ToListAsync(cancellationToken); da.CloseConnection(); return(result); }
public virtual async Task <IList <UserEntity> > GetPlayersInTeamAsync(long teamId, CancellationToken cancellationToken) { using var da = _dbContext.GetNewAdapter(); var metaData = new LinqMetaData(da); var result = await(from pit in metaData.PlayerInTeam where pit.TeamId == teamId select pit.User).ToListAsync(cancellationToken); _logger.LogTrace("{0} player(s) found for team id {1}", result.Count, teamId); return(result); }
/// <summary> /// Gets the <see cref="EntityCollection{TEntity}"/> of type <see cref="ExcludeMatchDateEntity"/> for a tournament. /// </summary> /// <param name="tournamentId"></param> /// <param name="cancellationToken"></param> /// <returns>Returns the <see cref="EntityCollection{TEntity}"/> of type <see cref="ExcludeMatchDateEntity"/> for a tournament.</returns> public async Task <EntityCollection <ExcludeMatchDateEntity> > GetExcludedMatchDatesAsync(long tournamentId, CancellationToken cancellationToken) { var excluded = new EntityCollection <ExcludeMatchDateEntity>(); using var da = _dbContext.GetNewAdapter(); var qp = new QueryParameters { CollectionToFetch = excluded, FilterToUse = ExcludeMatchDateFields.TournamentId == tournamentId }; await da.FetchEntityCollectionAsync(qp, cancellationToken); da.CloseConnection(); return(excluded); }
/// <summary> /// Gets the matches (<see cref="PlannedMatchRow"/>s) for a venue, which are occupied within the given <see cref="DateTimePeriod"/> of a tournament. /// </summary> /// <param name="venueId"></param> /// <param name="searchPeriod"></param> /// <param name="tournamentId"></param> /// <param name="cancellationToken"></param> /// <returns>Returns the matches (<see cref="PlannedMatchRow"/>s) for a venue, which are occupied within the given <see cref="DateTimePeriod"/> of a tournament.</returns> public virtual async Task <List <PlannedMatchRow> > GetOccupyingMatchesAsync(long venueId, DateTimePeriod searchPeriod, long tournamentId, CancellationToken cancellationToken) { using var da = _dbContext.GetNewAdapter(); var metaData = new LinqMetaData(da); var matchIds = await(from m in metaData.Match where m.Round.TournamentId == tournamentId && m.VenueId == venueId && !m.IsComplete && m.PlannedStart.HasValue && m.PlannedEnd.HasValue && (m.PlannedStart <= searchPeriod.End && searchPeriod.Start <= m.PlannedEnd) // overlapping periods select m.Id).ExecuteAsync <List <long> >(cancellationToken); var filter = new PredicateExpression(PlannedMatchFields.TournamentId == tournamentId); filter.AddWithAnd(PlannedMatchFields.Id.In(matchIds)); return(matchIds.Count > 0 ? await new MatchRepository(_dbContext).GetPlannedMatchesAsync(filter, cancellationToken) : new List <PlannedMatchRow>()); }
/// <summary> /// Gets an <see cref="IList{T}"/> of <see cref="TeamInRoundEntity"/>s matching the filter criteria. /// </summary> /// <param name="filter">The filter <see cref="IPredicateExpression"/> may contain <see cref="TeamInRoundFields"/> and <see cref="RoundFields"/>.</param> /// <param name="cancellationToken"></param> /// <returns>Returns an <see cref="IList{T}"/> of <see cref="TeamInRoundEntity"/>s matching the filter criteria.</returns> public virtual async Task <IList <TeamInRoundEntity> > GetTeamInRoundAsync(IPredicateExpression filter, CancellationToken cancellationToken) { using var da = _dbContext.GetNewAdapter(); var qf = new QueryFactory(); var q = qf.TeamInRound.From(QueryTarget.InnerJoin(qf.Round) .On(TeamInRoundFields.RoundId == RoundFields.Id)).Where(filter); return((IList <TeamInRoundEntity>) await da.FetchQueryAsync <TeamInRoundEntity>( q, cancellationToken)); }
public virtual async Task <IdentityUserTokenEntity> GetTokenAsync(long userId, string loginProvider, string name, CancellationToken cancellationToken) { using var da = _dbContext.GetNewAdapter(); var metaData = new LinqMetaData(da); var result = await (from token in metaData.IdentityUserToken where token.LoginProvider == loginProvider && token.Name == name select token).FirstOrDefaultAsync(cancellationToken); return(result); }
/// <summary> /// Gets a User or the Manager subtype. /// </summary> /// <param name="id"></param> /// <param name="cancellationToken"></param> /// <returns>Returns a User or the Manager subtype, or null if not found.</returns> public virtual async Task <UserEntity> GetLoginUserAsync(long id, CancellationToken cancellationToken) { using var da = _dbContext.GetNewAdapter(); var metaData = new LinqMetaData(da); var result = await(from u in metaData.User where u.Id == id select u).WithPath(new IPathEdge[] { new PathEdge <UserEntity>(UserEntity.PrefetchPathManagerOfTeams), new PathEdge <UserEntity>(UserEntity.PrefetchPathPlayerInTeams) }).ExecuteAsync <EntityCollection <UserEntity> >(cancellationToken); da.CloseConnection(); return(result.FirstOrDefault()); }
public virtual async Task <IdentityRoleEntity?> GetRoleByIdAsync(long id, CancellationToken cancellationToken) { using var da = _dbContext.GetNewAdapter(); var metaData = new LinqMetaData(da); var result = await(from r in metaData.IdentityRole where r.Id == id select r).FirstOrDefaultAsync(cancellationToken); return(result); }
public virtual bool SaveEntity <T>(T entityToSave, bool refetchAfterSave, bool recurse) where T : IEntity2 { var transactionName = Guid.NewGuid().ToString("N"); using var da = _dbContext.GetNewAdapter(); try { da.StartTransaction(IsolationLevel.ReadCommitted, transactionName); var success = da.SaveEntity(entityToSave, refetchAfterSave, recurse); da.Commit(); return(success); } catch (Exception) { if (da.IsTransactionInProgress) { da.Rollback(); } da.CloseConnection(); throw; } }
public virtual async Task <List <TeamVenueRoundRow> > GetTeamVenueRoundInfoAsync(IPredicateExpression filter, CancellationToken cancellationToken) { using var da = _dbContext.GetNewAdapter(); return(await da.FetchQueryAsync <TeamVenueRoundRow>( new QueryFactory().TeamVenueRound.Where(filter), cancellationToken)); }
public virtual async Task <MatchRuleEntity> GetMatchRuleAsync(long roundId, CancellationToken cancellationToken) { using var da = _dbContext.GetNewAdapter(); return(await new LinqMetaData(da).Round.Select(r => r.MatchRule).ExecuteAsync <MatchRuleEntity>(cancellationToken)); }
public virtual async Task <TournamentEntity?> GetTournamentAsync(PredicateExpression filter, CancellationToken cancellationToken) { using var da = _dbContext.GetNewAdapter(); return((await da.FetchQueryAsync <TournamentEntity>( new QueryFactory().Tournament.Where(filter), cancellationToken)).Cast <TournamentEntity>().FirstOrDefault()); }
public virtual async Task SaveAsync(RankingList rankingList, long roundId, CancellationToken cancellationToken) { var rankingColl = new EntityCollection <RankingEntity>(new RankingEntityFactory()); var da = _dbContext.GetNewAdapter(); var transactionName = nameof(SaveAsync) + Guid.NewGuid().ToString("N"); try { // Todo: TournamentId is defined via the Round - remove TournamentId from the Ranking table. View RankingList does not depend on TournamentId already. var tournamentId = await GetTournamentIdOfRoundAsync(roundId, cancellationToken); // Fetch existing ranking entities for the round for deletion var existingEntities = new EntityCollection <RankingEntity> { RemovedEntitiesTracker = new EntityCollection() }; var qp = new QueryParameters { CollectionToFetch = existingEntities, FilterToUse = RankingFields.RoundId == roundId, ExcludedIncludedFields = new IncludeFieldsList(RankingFields.Id) }; await da.FetchEntityCollectionAsync(qp, cancellationToken); // Create ranking entities foreach (var rank in rankingList) { rankingColl.Add(new RankingEntity { TournamentId = tournamentId, RoundId = roundId, Rank = rank.Number, ValuationDate = rankingList.UpperDateLimit, TeamId = rank.TeamId, MatchPointsWon = rank.MatchPoints.Home, MatchPointsLost = rank.MatchPoints.Guest, SetPointsWon = rank.SetPoints.Home, SetPointsLost = rank.SetPoints.Guest, BallPointsWon = rank.BallPoints.Home, BallPointsLost = rank.BallPoints.Guest, MatchesPlayed = rank.MatchesPlayed, MatchesToPlay = rank.MatchesToPlay, CreatedOn = DateTime.UtcNow, ModifiedOn = rankingList.LastUpdatedOn }); } // Start a transaction to store in the database await da.StartTransactionAsync(IsolationLevel.ReadCommitted, transactionName, cancellationToken); // Remove all existing ranking entities for the round //existingEntities.RemoveRange(existingEntities); await da.DeleteEntityCollectionAsync(existingEntities, cancellationToken); // Save the new ranking entities await da.SaveEntityCollectionAsync(rankingColl, false, false, cancellationToken); da.Commit(); } catch (Exception e) { _logger.LogCritical(e, $"Ranking for round id {roundId}"); if (da.IsTransactionInProgress) { da.Rollback(); } throw; } finally { da.CloseConnection(); da.Dispose(); } }