public async Task <IEnumerable <TeamDto> > GetForMatchAsync(ScopedFilter filter, int match) { var mo = (await _matchService.FindById(match)).AsModel(this._context); var clubs = await this._context.Teams.Where(t => t.MatchTeams.All(m => m.MatchId != match) && mo.Day.League.Id == t.League.Id).ToListAsync(); return(clubs.Select(c => c.MapToTeamDto())); }
public static void AddScopedFilter <TContext, T>(this IPipeConfigurator <TContext> configurator, Type scopedType, IServiceProvider provider) where TContext : class, PipeContext where T : class { if (typeof(T).HasInterface <Fault>()) { return; } if (!scopedType.IsGenericType || !scopedType.IsGenericTypeDefinition) { throw new ArgumentException("The scoped filter must be a generic type definition", nameof(scopedType)); } var filterType = scopedType.MakeGenericType(typeof(T)); if (!filterType.HasInterface(typeof(IFilter <TContext>))) { throw new ArgumentException($"The scoped filter must implement {TypeMetadataCache<IFilter<TContext>>.ShortName} ", nameof(scopedType)); } var scopeProviderType = typeof(DependencyInjectionFilterContextScopeProvider <,>).MakeGenericType(filterType, typeof(TContext)); var scopeProvider = (IFilterContextScopeProvider <TContext>)Activator.CreateInstance(scopeProviderType, provider); var filter = new ScopedFilter <TContext>(scopeProvider); var specification = new FilterPipeSpecification <TContext>(filter); configurator.AddPipeSpecification(specification); }
public void MessageSpecificationCreated <T>(IMessageSendPipeSpecification <T> specification) where T : class { var scopeProviderType = typeof(AutofacFilterContextScopeProvider <,>).MakeGenericType(_filterType.MakeGenericType(typeof(T)), typeof(SendContext <T>)); var scopeProvider = (IFilterContextScopeProvider <SendContext <T> >)Activator.CreateInstance(scopeProviderType, _lifetimeScopeProvider); var filter = new ScopedFilter <SendContext <T> >(scopeProvider); specification.UseFilter(filter); }
public void MessageSpecificationCreated <T>(IMessagePublishPipeSpecification <T> specification) where T : class { var scopeProviderType = typeof(DependencyInjectionFilterContextScopeProvider <,>).MakeGenericType(_filterType.MakeGenericType(typeof(T)), typeof(PublishContext <T>)); var scopeProvider = (IFilterContextScopeProvider <PublishContext <T> >)Activator.CreateInstance(scopeProviderType, _serviceProvider); var filter = new ScopedFilter <PublishContext <T> >(scopeProvider); specification.UseFilter(filter); }
private IQueryable <Team> ScopedTeams(ScopedFilter filter) { IQueryable <Team> teams = this._context.Teams; if (filter == ScopedFilter.Manager) { var userId = this._userService.CurrentUser().Id; teams = teams.Where(c => c.Club.Manager.Id == userId); } return(teams); }
public void CompensateActivityConfigured <TActivity, TLog>(ICompensateActivityConfigurator <TActivity, TLog> configurator) where TActivity : class, ICompensateActivity <TLog> where TLog : class { var scopeProviderType = typeof(AutofacFilterContextScopeProvider <,>).MakeGenericType(_filterType.MakeGenericType(typeof(TLog)), typeof(CompensateContext <TLog>)); var scopeProvider = (IFilterContextScopeProvider <CompensateContext <TLog> >)Activator.CreateInstance(scopeProviderType, _lifetimeScopeProvider); var filter = new ScopedFilter <CompensateContext <TLog> >(scopeProvider); configurator.Log(a => a.UseFilter(filter)); }
public void ExecuteActivityConfigured <TActivity, TArguments>(IExecuteActivityConfigurator <TActivity, TArguments> configurator) where TActivity : class, IExecuteActivity <TArguments> where TArguments : class { var scopeProviderType = typeof(DependencyInjectionFilterContextScopeProvider <,>).MakeGenericType(_filterType.MakeGenericType(typeof(TArguments)), typeof(ExecuteContext <TArguments>)); var scopeProvider = (IFilterContextScopeProvider <ExecuteContext <TArguments> >)Activator.CreateInstance(scopeProviderType, _serviceProvider); var filter = new ScopedFilter <ExecuteContext <TArguments> >(scopeProvider); configurator.Arguments(a => a.UseFilter(filter)); }
public void MessageConfigured <TMessage>(IConsumePipeConfigurator configurator) where TMessage : class { var scopeProviderType = typeof(AutofacFilterContextScopeProvider <,>).MakeGenericType(_filterType.MakeGenericType(typeof(TMessage)), typeof(ConsumeContext <TMessage>)); var scopeProvider = (IFilterContextScopeProvider <ConsumeContext <TMessage> >)Activator.CreateInstance(scopeProviderType, _lifetimeScopeProvider); var filter = new ScopedFilter <ConsumeContext <TMessage> >(scopeProvider); var specification = new FilterPipeSpecification <ConsumeContext <TMessage> >(filter); configurator.AddPipeSpecification(specification); }
public void ConsumerMessageConfigured <TConsumer, TMessage>(IConsumerMessageConfigurator <TConsumer, TMessage> configurator) where TConsumer : class where TMessage : class { var scopeProviderType = typeof(DependencyInjectionFilterContextScopeProvider <,>) .MakeGenericType(_filterType.MakeGenericType(typeof(TMessage)), typeof(ConsumeContext <TMessage>)); var scopeProvider = (IFilterContextScopeProvider <ConsumeContext <TMessage> >)Activator.CreateInstance(scopeProviderType, _serviceProvider); var filter = new ScopedFilter <ConsumeContext <TMessage> >(scopeProvider); var specification = new FilterPipeSpecification <ConsumeContext <TMessage> >(filter); configurator.Message(m => m.AddPipeSpecification(specification)); }
public async Task <IEnumerable <TeamDto> > GetByClubAsync(ScopedFilter filter, int clubId) { var clubs = await this._context.Teams.Where(t => t.Club.Id == clubId).ToListAsync(); return(clubs.Select(c => c.MapToTeamDto())); }
public async Task <IEnumerable <TeamDto> > GetAsync(ScopedFilter filter) { var teams = await this.ScopedTeams(filter).ToListAsync(); return(teams.Select(TeamExtensions.MapToTeamDto)); }
public async Task <IEnumerable <ClubDto> > GetAsync(ScopedFilter filter) { var clubs = await _context.Clubs.Where(c => filter == ScopedFilter.All || c.Manager == this._userService.CurrentUser()).ToListAsync(); return(clubs.Select(ClubExtensions.MapToClubDto)); }