public void AddTag(string url, string name, string value, int accessLevel) { using (var context = contextProvider.GetContext()) { var site = context.Sites.Include(s => s.Tags).FirstOrDefault(s => s.Url == url); if (site == null) { site = new Site { Url = url, Tags = new List <Tag>(), AccessLevel = accessLevel }; context.Sites.Add(site); } else if (site.AccessLevel < accessLevel) { site.AccessLevel = accessLevel; } site.Tags.Add(new Tag { Name = name, Site = site, Value = value }); context.SaveChanges(); } }
public ICollection <Site> List(int accessLevel) { using (var context = contextProvider.GetContext()) { return(context.Sites.Where(s => s.AccessLevel <= accessLevel).ToList()); } }
public async Task <ILookup <int, Datasource> > GetDatasourcesPerProject(IEnumerable <int> projectIds) { List <Datasource> datasources = new List <Datasource>(); foreach (var projectId in projectIds.Distinct()) { var context = _contextProvider.GetContext(projectId); var result = await context.Datasource.Where(x => projectId == x.ProjectId).ToListAsync(); datasources.AddRange(result); } return(datasources.ToLookup(x => x.ProjectId)); }
protected BaseRepository( IDbContextProvider <TEntity> contextProvider) { Collection = contextProvider.GetContext(); }
private IDbContext GetContext() => _dbContextProvider.GetContext();
private DbSet <TEntity> GetTableInternal <TEntity>() where TEntity : class, IEntity { return(dbContextProvider.GetContext().Set <TEntity>()); }
/// <summary> /// Gets the localized query. /// </summary> /// <param name="cultureId">The culture identifier.</param> /// <returns>The query.</returns> protected override IQueryable <Tables> GetLocalizedQuery(long cultureId) => _dbContextProvider.GetContext().GetTables(cultureId);
public SettingGroups Get(long pluginId, string code) => _dbContextProvider .GetContext() .Table<SettingGroups>() .FirstOrDefault(item => (item.OwnerPluginId == pluginId) && (item.Code == code));
public TDbContext GetContext(object dbIndex = null) { return(_contextProvider.GetContext <TDbContext>(dbIndex)); }
public EFGenericRepository(IDbContextProvider contextProvider) { _context = contextProvider.GetContext(); _dbSet = _context.Set <TEntity>(); }