update to load the data in scope.
This commit is contained in:
parent
055e54966d
commit
0cafef7ab4
|
@ -13,7 +13,6 @@ namespace Oqtane.Repository
|
||||||
public class FileRepository : IFileRepository
|
public class FileRepository : IFileRepository
|
||||||
{
|
{
|
||||||
private readonly IDbContextFactory<TenantDBContext> _dbContextFactory;
|
private readonly IDbContextFactory<TenantDBContext> _dbContextFactory;
|
||||||
private readonly TenantDBContext _queryContext;
|
|
||||||
private readonly IPermissionRepository _permissions;
|
private readonly IPermissionRepository _permissions;
|
||||||
private readonly IFolderRepository _folderRepository;
|
private readonly IFolderRepository _folderRepository;
|
||||||
private readonly ITenantManager _tenants;
|
private readonly ITenantManager _tenants;
|
||||||
|
@ -21,7 +20,6 @@ namespace Oqtane.Repository
|
||||||
public FileRepository(IDbContextFactory<TenantDBContext> dbContextFactory, IPermissionRepository permissions, IFolderRepository folderRepository, ITenantManager tenants)
|
public FileRepository(IDbContextFactory<TenantDBContext> dbContextFactory, IPermissionRepository permissions, IFolderRepository folderRepository, ITenantManager tenants)
|
||||||
{
|
{
|
||||||
_dbContextFactory = dbContextFactory;
|
_dbContextFactory = dbContextFactory;
|
||||||
_queryContext = dbContextFactory.CreateDbContext();
|
|
||||||
_permissions = permissions;
|
_permissions = permissions;
|
||||||
_folderRepository = folderRepository;
|
_folderRepository = folderRepository;
|
||||||
_tenants = tenants;
|
_tenants = tenants;
|
||||||
|
@ -34,20 +32,21 @@ namespace Oqtane.Repository
|
||||||
|
|
||||||
public IEnumerable<File> GetFiles(int folderId, bool tracking)
|
public IEnumerable<File> GetFiles(int folderId, bool tracking)
|
||||||
{
|
{
|
||||||
|
using var db = _dbContextFactory.CreateDbContext();
|
||||||
var folder = _folderRepository.GetFolder(folderId, false);
|
var folder = _folderRepository.GetFolder(folderId, false);
|
||||||
IEnumerable<Permission> permissions = _permissions.GetPermissions(folder.SiteId, EntityNames.Folder, folderId).ToList();
|
var permissions = _permissions.GetPermissions(folder.SiteId, EntityNames.Folder, folderId).ToList();
|
||||||
|
|
||||||
IEnumerable<File> files;
|
IEnumerable<File> files;
|
||||||
if (tracking)
|
if (tracking)
|
||||||
{
|
{
|
||||||
files = _queryContext.File.Where(item => item.FolderId == folderId).Include(item => item.Folder);
|
files = db.File.Where(item => item.FolderId == folderId).Include(item => item.Folder).ToList();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
files = _queryContext.File.AsNoTracking().Where(item => item.FolderId == folderId).Include(item => item.Folder);
|
files = db.File.AsNoTracking().Where(item => item.FolderId == folderId).Include(item => item.Folder).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (File file in files)
|
foreach (var file in files)
|
||||||
{
|
{
|
||||||
file.Folder.PermissionList = permissions.ToList();
|
file.Folder.PermissionList = permissions.ToList();
|
||||||
var alias = _tenants.GetAlias();
|
var alias = _tenants.GetAlias();
|
||||||
|
|
|
@ -12,7 +12,6 @@ namespace Oqtane.Repository
|
||||||
public class FolderRepository : IFolderRepository
|
public class FolderRepository : IFolderRepository
|
||||||
{
|
{
|
||||||
private readonly IDbContextFactory<TenantDBContext> _dbContextFactory;
|
private readonly IDbContextFactory<TenantDBContext> _dbContextFactory;
|
||||||
private readonly TenantDBContext _queryContext;
|
|
||||||
private readonly IPermissionRepository _permissions;
|
private readonly IPermissionRepository _permissions;
|
||||||
private readonly IWebHostEnvironment _environment;
|
private readonly IWebHostEnvironment _environment;
|
||||||
private readonly ITenantManager _tenants;
|
private readonly ITenantManager _tenants;
|
||||||
|
@ -20,7 +19,6 @@ namespace Oqtane.Repository
|
||||||
public FolderRepository(IDbContextFactory<TenantDBContext> dbContextFactory, IPermissionRepository permissions,IWebHostEnvironment environment, ITenantManager tenants)
|
public FolderRepository(IDbContextFactory<TenantDBContext> dbContextFactory, IPermissionRepository permissions,IWebHostEnvironment environment, ITenantManager tenants)
|
||||||
{
|
{
|
||||||
_dbContextFactory = dbContextFactory;
|
_dbContextFactory = dbContextFactory;
|
||||||
_queryContext = _dbContextFactory.CreateDbContext();
|
|
||||||
_permissions = permissions;
|
_permissions = permissions;
|
||||||
_environment = environment;
|
_environment = environment;
|
||||||
_tenants = tenants;
|
_tenants = tenants;
|
||||||
|
@ -28,8 +26,9 @@ namespace Oqtane.Repository
|
||||||
|
|
||||||
public IEnumerable<Folder> GetFolders(int siteId)
|
public IEnumerable<Folder> GetFolders(int siteId)
|
||||||
{
|
{
|
||||||
|
using var db = _dbContextFactory.CreateDbContext();
|
||||||
var permissions = _permissions.GetPermissions(siteId, EntityNames.Folder).ToList();
|
var permissions = _permissions.GetPermissions(siteId, EntityNames.Folder).ToList();
|
||||||
var folders = _queryContext.Folder.Where(item => item.SiteId == siteId);
|
var folders = db.Folder.Where(item => item.SiteId == siteId).ToList();
|
||||||
foreach (var folder in folders)
|
foreach (var folder in folders)
|
||||||
{
|
{
|
||||||
folder.PermissionList = permissions.Where(item => item.EntityId == folder.FolderId).ToList();
|
folder.PermissionList = permissions.Where(item => item.EntityId == folder.FolderId).ToList();
|
||||||
|
|
|
@ -8,17 +8,16 @@ namespace Oqtane.Repository
|
||||||
public class LanguageRepository : ILanguageRepository
|
public class LanguageRepository : ILanguageRepository
|
||||||
{
|
{
|
||||||
private readonly IDbContextFactory<TenantDBContext> _dbContextFactory;
|
private readonly IDbContextFactory<TenantDBContext> _dbContextFactory;
|
||||||
private readonly TenantDBContext _queryContext;
|
|
||||||
|
|
||||||
public LanguageRepository(IDbContextFactory<TenantDBContext> dbContextFactory)
|
public LanguageRepository(IDbContextFactory<TenantDBContext> dbContextFactory)
|
||||||
{
|
{
|
||||||
_dbContextFactory = dbContextFactory;
|
_dbContextFactory = dbContextFactory;
|
||||||
_queryContext = _dbContextFactory.CreateDbContext();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Language> GetLanguages(int siteId)
|
public IEnumerable<Language> GetLanguages(int siteId)
|
||||||
{
|
{
|
||||||
return _queryContext.Language.Where(l => l.SiteId == siteId);
|
using var db = _dbContextFactory.CreateDbContext();
|
||||||
|
return db.Language.Where(l => l.SiteId == siteId).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Language AddLanguage(Language language)
|
public Language AddLanguage(Language language)
|
||||||
|
|
|
@ -9,36 +9,35 @@ namespace Oqtane.Repository
|
||||||
public class LogRepository : ILogRepository
|
public class LogRepository : ILogRepository
|
||||||
{
|
{
|
||||||
private readonly IDbContextFactory<TenantDBContext> _dbContextFactory;
|
private readonly IDbContextFactory<TenantDBContext> _dbContextFactory;
|
||||||
private readonly TenantDBContext _queryContext;
|
|
||||||
|
|
||||||
public LogRepository(IDbContextFactory<TenantDBContext> dbContextFactory)
|
public LogRepository(IDbContextFactory<TenantDBContext> dbContextFactory)
|
||||||
{
|
{
|
||||||
_dbContextFactory = dbContextFactory;
|
_dbContextFactory = dbContextFactory;
|
||||||
_queryContext = _dbContextFactory.CreateDbContext();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Log> GetLogs(int siteId, string level, string function, int rows)
|
public IEnumerable<Log> GetLogs(int siteId, string level, string function, int rows)
|
||||||
{
|
{
|
||||||
|
using var db = _dbContextFactory.CreateDbContext();
|
||||||
if (level == null)
|
if (level == null)
|
||||||
{
|
{
|
||||||
if (function == null)
|
if (function == null)
|
||||||
{
|
{
|
||||||
return _queryContext.Log.Where(item => item.SiteId == siteId).
|
return db.Log.Where(item => item.SiteId == siteId).
|
||||||
OrderByDescending(item => item.LogDate).Take(rows);
|
OrderByDescending(item => item.LogDate).Take(rows).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
return _queryContext.Log.Where(item => item.SiteId == siteId && item.Function == function).
|
return db.Log.Where(item => item.SiteId == siteId && item.Function == function).
|
||||||
OrderByDescending(item => item.LogDate).Take(rows);
|
OrderByDescending(item => item.LogDate).Take(rows).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (function == null)
|
if (function == null)
|
||||||
{
|
{
|
||||||
return _queryContext.Log.Where(item => item.SiteId == siteId && item.Level == level)
|
return db.Log.Where(item => item.SiteId == siteId && item.Level == level)
|
||||||
.OrderByDescending(item => item.LogDate).Take(rows);
|
.OrderByDescending(item => item.LogDate).Take(rows).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
return _queryContext.Log.Where(item => item.SiteId == siteId && item.Level == level && item.Function == function)
|
return db.Log.Where(item => item.SiteId == siteId && item.Level == level && item.Function == function)
|
||||||
.OrderByDescending(item => item.LogDate).Take(rows);
|
.OrderByDescending(item => item.LogDate).Take(rows).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Log GetLog(int logId)
|
public Log GetLog(int logId)
|
||||||
|
|
|
@ -15,7 +15,6 @@ namespace Oqtane.Repository
|
||||||
public class ModuleRepository : IModuleRepository
|
public class ModuleRepository : IModuleRepository
|
||||||
{
|
{
|
||||||
private readonly IDbContextFactory<TenantDBContext> _dbContextFactory;
|
private readonly IDbContextFactory<TenantDBContext> _dbContextFactory;
|
||||||
private readonly TenantDBContext _queryContext;
|
|
||||||
private readonly IPermissionRepository _permissions;
|
private readonly IPermissionRepository _permissions;
|
||||||
private readonly ISettingRepository _settings;
|
private readonly ISettingRepository _settings;
|
||||||
private readonly IModuleDefinitionRepository _moduleDefinitions;
|
private readonly IModuleDefinitionRepository _moduleDefinitions;
|
||||||
|
@ -24,7 +23,6 @@ namespace Oqtane.Repository
|
||||||
public ModuleRepository(IDbContextFactory<TenantDBContext> dbContextFactory, IPermissionRepository permissions, ISettingRepository settings, IModuleDefinitionRepository moduleDefinitions, IServiceProvider serviceProvider)
|
public ModuleRepository(IDbContextFactory<TenantDBContext> dbContextFactory, IPermissionRepository permissions, ISettingRepository settings, IModuleDefinitionRepository moduleDefinitions, IServiceProvider serviceProvider)
|
||||||
{
|
{
|
||||||
_dbContextFactory = dbContextFactory;
|
_dbContextFactory = dbContextFactory;
|
||||||
_queryContext = _dbContextFactory.CreateDbContext();
|
|
||||||
_permissions = permissions;
|
_permissions = permissions;
|
||||||
_settings = settings;
|
_settings = settings;
|
||||||
_moduleDefinitions = moduleDefinitions;
|
_moduleDefinitions = moduleDefinitions;
|
||||||
|
@ -33,7 +31,8 @@ namespace Oqtane.Repository
|
||||||
|
|
||||||
public IEnumerable<Module> GetModules(int siteId)
|
public IEnumerable<Module> GetModules(int siteId)
|
||||||
{
|
{
|
||||||
return _queryContext.Module.Where(item => item.SiteId == siteId);
|
using var db = _dbContextFactory.CreateDbContext();
|
||||||
|
return db.Module.Where(item => item.SiteId == siteId).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Module AddModule(Module module)
|
public Module AddModule(Module module)
|
||||||
|
|
|
@ -10,7 +10,6 @@ namespace Oqtane.Repository
|
||||||
public class PageRepository : IPageRepository
|
public class PageRepository : IPageRepository
|
||||||
{
|
{
|
||||||
private readonly IDbContextFactory<TenantDBContext> _dbContextFactory;
|
private readonly IDbContextFactory<TenantDBContext> _dbContextFactory;
|
||||||
private readonly TenantDBContext _queryContext;
|
|
||||||
private readonly IPageModuleRepository _pageModules;
|
private readonly IPageModuleRepository _pageModules;
|
||||||
private readonly IPermissionRepository _permissions;
|
private readonly IPermissionRepository _permissions;
|
||||||
private readonly ISettingRepository _settings;
|
private readonly ISettingRepository _settings;
|
||||||
|
@ -18,7 +17,6 @@ namespace Oqtane.Repository
|
||||||
public PageRepository(IDbContextFactory<TenantDBContext> dbContextFactory, IPageModuleRepository pageModules, IPermissionRepository permissions, ISettingRepository settings)
|
public PageRepository(IDbContextFactory<TenantDBContext> dbContextFactory, IPageModuleRepository pageModules, IPermissionRepository permissions, ISettingRepository settings)
|
||||||
{
|
{
|
||||||
_dbContextFactory = dbContextFactory;
|
_dbContextFactory = dbContextFactory;
|
||||||
_queryContext = _dbContextFactory.CreateDbContext();
|
|
||||||
_pageModules = pageModules;
|
_pageModules = pageModules;
|
||||||
_permissions = permissions;
|
_permissions = permissions;
|
||||||
_settings = settings;
|
_settings = settings;
|
||||||
|
@ -26,8 +24,9 @@ namespace Oqtane.Repository
|
||||||
|
|
||||||
public IEnumerable<Page> GetPages(int siteId)
|
public IEnumerable<Page> GetPages(int siteId)
|
||||||
{
|
{
|
||||||
|
using var db = _dbContextFactory.CreateDbContext();
|
||||||
var permissions = _permissions.GetPermissions(siteId, EntityNames.Page).ToList();
|
var permissions = _permissions.GetPermissions(siteId, EntityNames.Page).ToList();
|
||||||
var pages = _queryContext.Page.Where(item => item.SiteId == siteId && item.UserId == null);
|
var pages = db.Page.Where(item => item.SiteId == siteId && item.UserId == null).ToList();
|
||||||
foreach (var page in pages)
|
foreach (var page in pages)
|
||||||
{
|
{
|
||||||
page.PermissionList = permissions.Where(item => item.EntityId == page.PageId).ToList();
|
page.PermissionList = permissions.Where(item => item.EntityId == page.PageId).ToList();
|
||||||
|
|
|
@ -8,17 +8,16 @@ namespace Oqtane.Repository
|
||||||
public class ProfileRepository : IProfileRepository
|
public class ProfileRepository : IProfileRepository
|
||||||
{
|
{
|
||||||
private readonly IDbContextFactory<TenantDBContext> _dbContextFactory;
|
private readonly IDbContextFactory<TenantDBContext> _dbContextFactory;
|
||||||
private readonly TenantDBContext _queryContext;
|
|
||||||
|
|
||||||
public ProfileRepository(IDbContextFactory<TenantDBContext> dbContextFactory)
|
public ProfileRepository(IDbContextFactory<TenantDBContext> dbContextFactory)
|
||||||
{
|
{
|
||||||
_dbContextFactory = dbContextFactory;
|
_dbContextFactory = dbContextFactory;
|
||||||
_queryContext = _dbContextFactory.CreateDbContext();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Profile> GetProfiles(int siteId)
|
public IEnumerable<Profile> GetProfiles(int siteId)
|
||||||
{
|
{
|
||||||
return _queryContext.Profile.Where(item => item.SiteId == siteId || item.SiteId == null);
|
using var db = _dbContextFactory.CreateDbContext();
|
||||||
|
return db.Profile.Where(item => item.SiteId == siteId || item.SiteId == null).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Profile AddProfile(Profile profile)
|
public Profile AddProfile(Profile profile)
|
||||||
|
|
|
@ -8,12 +8,10 @@ namespace Oqtane.Repository
|
||||||
public class RoleRepository : IRoleRepository
|
public class RoleRepository : IRoleRepository
|
||||||
{
|
{
|
||||||
private readonly IDbContextFactory<TenantDBContext> _dbContextFactory;
|
private readonly IDbContextFactory<TenantDBContext> _dbContextFactory;
|
||||||
private readonly TenantDBContext _queryContext;
|
|
||||||
|
|
||||||
public RoleRepository(IDbContextFactory<TenantDBContext> dbContextFactory)
|
public RoleRepository(IDbContextFactory<TenantDBContext> dbContextFactory)
|
||||||
{
|
{
|
||||||
_dbContextFactory = dbContextFactory;
|
_dbContextFactory = dbContextFactory;
|
||||||
_queryContext = _dbContextFactory.CreateDbContext();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Role> GetRoles(int siteId)
|
public IEnumerable<Role> GetRoles(int siteId)
|
||||||
|
@ -23,13 +21,14 @@ namespace Oqtane.Repository
|
||||||
|
|
||||||
public IEnumerable<Role> GetRoles(int siteId, bool includeGlobalRoles)
|
public IEnumerable<Role> GetRoles(int siteId, bool includeGlobalRoles)
|
||||||
{
|
{
|
||||||
|
using var db = _dbContextFactory.CreateDbContext();
|
||||||
if (includeGlobalRoles)
|
if (includeGlobalRoles)
|
||||||
{
|
{
|
||||||
return _queryContext.Role.Where(item => item.SiteId == siteId || item.SiteId == null);
|
return db.Role.Where(item => item.SiteId == siteId || item.SiteId == null).ToList();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return _queryContext.Role.Where(item => item.SiteId == siteId);
|
return db.Role.Where(item => item.SiteId == siteId).ToList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,6 @@ namespace Oqtane.Repository
|
||||||
public class SettingRepository : ISettingRepository
|
public class SettingRepository : ISettingRepository
|
||||||
{
|
{
|
||||||
private readonly IDbContextFactory<TenantDBContext> _tenantContextFactory;
|
private readonly IDbContextFactory<TenantDBContext> _tenantContextFactory;
|
||||||
private readonly TenantDBContext _tenantQueryContext;
|
|
||||||
private MasterDBContext _master;
|
private MasterDBContext _master;
|
||||||
private readonly ITenantManager _tenantManager;
|
private readonly ITenantManager _tenantManager;
|
||||||
private readonly IMemoryCache _cache;
|
private readonly IMemoryCache _cache;
|
||||||
|
@ -20,7 +19,6 @@ namespace Oqtane.Repository
|
||||||
public SettingRepository(IDbContextFactory<TenantDBContext> tenantContextFactory, MasterDBContext master, ITenantManager tenantManager, IMemoryCache cache)
|
public SettingRepository(IDbContextFactory<TenantDBContext> tenantContextFactory, MasterDBContext master, ITenantManager tenantManager, IMemoryCache cache)
|
||||||
{
|
{
|
||||||
_tenantContextFactory = tenantContextFactory;
|
_tenantContextFactory = tenantContextFactory;
|
||||||
_tenantQueryContext = tenantContextFactory.CreateDbContext();
|
|
||||||
_master = master;
|
_master = master;
|
||||||
_tenantManager = tenantManager;
|
_tenantManager = tenantManager;
|
||||||
_cache = cache;
|
_cache = cache;
|
||||||
|
@ -34,7 +32,8 @@ namespace Oqtane.Repository
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return _tenantQueryContext.Setting.Where(item => item.EntityName == entityName);
|
using var db = _tenantContextFactory.CreateDbContext();
|
||||||
|
return db.Setting.Where(item => item.EntityName == entityName).ToList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Internal;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Oqtane.Enums;
|
using Oqtane.Enums;
|
||||||
|
@ -18,7 +19,6 @@ namespace Oqtane.Repository
|
||||||
public class SiteRepository : ISiteRepository
|
public class SiteRepository : ISiteRepository
|
||||||
{
|
{
|
||||||
private readonly IDbContextFactory<TenantDBContext> _factory;
|
private readonly IDbContextFactory<TenantDBContext> _factory;
|
||||||
private readonly TenantDBContext _queryContext;
|
|
||||||
private readonly IRoleRepository _roleRepository;
|
private readonly IRoleRepository _roleRepository;
|
||||||
private readonly IProfileRepository _profileRepository;
|
private readonly IProfileRepository _profileRepository;
|
||||||
private readonly IFolderRepository _folderRepository;
|
private readonly IFolderRepository _folderRepository;
|
||||||
|
@ -38,7 +38,6 @@ namespace Oqtane.Repository
|
||||||
IConfigurationRoot config, IServerStateManager serverState, ILogManager logger)
|
IConfigurationRoot config, IServerStateManager serverState, ILogManager logger)
|
||||||
{
|
{
|
||||||
_factory = factory;
|
_factory = factory;
|
||||||
_queryContext = _factory.CreateDbContext();
|
|
||||||
_roleRepository = roleRepository;
|
_roleRepository = roleRepository;
|
||||||
_profileRepository = profileRepository;
|
_profileRepository = profileRepository;
|
||||||
_folderRepository = folderRepository;
|
_folderRepository = folderRepository;
|
||||||
|
@ -107,7 +106,8 @@ namespace Oqtane.Repository
|
||||||
// synchronous methods
|
// synchronous methods
|
||||||
public IEnumerable<Site> GetSites()
|
public IEnumerable<Site> GetSites()
|
||||||
{
|
{
|
||||||
return _queryContext.Site.OrderBy(item => item.Name);
|
using var db = _factory.CreateDbContext();
|
||||||
|
return db.Site.OrderBy(item => item.Name).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Site AddSite(Site site)
|
public Site AddSite(Site site)
|
||||||
|
|
|
@ -9,25 +9,24 @@ namespace Oqtane.Repository
|
||||||
public class UrlMappingRepository : IUrlMappingRepository
|
public class UrlMappingRepository : IUrlMappingRepository
|
||||||
{
|
{
|
||||||
private readonly IDbContextFactory<TenantDBContext> _dbContextFactory;
|
private readonly IDbContextFactory<TenantDBContext> _dbContextFactory;
|
||||||
private readonly TenantDBContext _queryContext;
|
|
||||||
private readonly ISiteRepository _sites;
|
private readonly ISiteRepository _sites;
|
||||||
|
|
||||||
public UrlMappingRepository(IDbContextFactory<TenantDBContext> dbContextFactory, ISiteRepository sites)
|
public UrlMappingRepository(IDbContextFactory<TenantDBContext> dbContextFactory, ISiteRepository sites)
|
||||||
{
|
{
|
||||||
_dbContextFactory = dbContextFactory;
|
_dbContextFactory = dbContextFactory;
|
||||||
_queryContext = _dbContextFactory.CreateDbContext();
|
|
||||||
_sites = sites;
|
_sites = sites;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<UrlMapping> GetUrlMappings(int siteId, bool isMapped)
|
public IEnumerable<UrlMapping> GetUrlMappings(int siteId, bool isMapped)
|
||||||
{
|
{
|
||||||
|
using var db = _dbContextFactory.CreateDbContext();
|
||||||
if (isMapped)
|
if (isMapped)
|
||||||
{
|
{
|
||||||
return _queryContext.UrlMapping.Where(item => item.SiteId == siteId && !string.IsNullOrEmpty(item.MappedUrl)).Take(200);
|
return db.UrlMapping.Where(item => item.SiteId == siteId && !string.IsNullOrEmpty(item.MappedUrl)).Take(200).ToList();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return _queryContext.UrlMapping.Where(item => item.SiteId == siteId && string.IsNullOrEmpty(item.MappedUrl)).Take(200);
|
return db.UrlMapping.Where(item => item.SiteId == siteId && string.IsNullOrEmpty(item.MappedUrl)).Take(200).ToList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,6 @@ namespace Oqtane.Repository
|
||||||
public class UserRepository : IUserRepository
|
public class UserRepository : IUserRepository
|
||||||
{
|
{
|
||||||
private readonly IDbContextFactory<TenantDBContext> _dbContextFactory;
|
private readonly IDbContextFactory<TenantDBContext> _dbContextFactory;
|
||||||
private readonly TenantDBContext _queryContext;
|
|
||||||
private readonly IFolderRepository _folders;
|
private readonly IFolderRepository _folders;
|
||||||
private readonly IRoleRepository _roles;
|
private readonly IRoleRepository _roles;
|
||||||
private readonly IUserRoleRepository _userroles;
|
private readonly IUserRoleRepository _userroles;
|
||||||
|
@ -17,7 +16,6 @@ namespace Oqtane.Repository
|
||||||
public UserRepository(IDbContextFactory<TenantDBContext> dbContextFactory, IFolderRepository folders, IRoleRepository roles, IUserRoleRepository userroles)
|
public UserRepository(IDbContextFactory<TenantDBContext> dbContextFactory, IFolderRepository folders, IRoleRepository roles, IUserRoleRepository userroles)
|
||||||
{
|
{
|
||||||
_dbContextFactory = dbContextFactory;
|
_dbContextFactory = dbContextFactory;
|
||||||
_queryContext = _dbContextFactory.CreateDbContext();
|
|
||||||
_folders = folders;
|
_folders = folders;
|
||||||
_roles = roles;
|
_roles = roles;
|
||||||
_userroles = userroles;
|
_userroles = userroles;
|
||||||
|
@ -25,7 +23,8 @@ namespace Oqtane.Repository
|
||||||
|
|
||||||
public IEnumerable<User> GetUsers()
|
public IEnumerable<User> GetUsers()
|
||||||
{
|
{
|
||||||
return _queryContext.User;
|
using var db = _dbContextFactory.CreateDbContext();
|
||||||
|
return db.User.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public User AddUser(User user)
|
public User AddUser(User user)
|
||||||
|
|
|
@ -9,30 +9,30 @@ namespace Oqtane.Repository
|
||||||
public class UserRoleRepository : IUserRoleRepository
|
public class UserRoleRepository : IUserRoleRepository
|
||||||
{
|
{
|
||||||
private readonly IDbContextFactory<TenantDBContext> _dbContextFactory;
|
private readonly IDbContextFactory<TenantDBContext> _dbContextFactory;
|
||||||
private readonly TenantDBContext _queryContext;
|
|
||||||
private readonly IRoleRepository _roles;
|
private readonly IRoleRepository _roles;
|
||||||
|
|
||||||
public UserRoleRepository(IDbContextFactory<TenantDBContext> dbContextFactory, IRoleRepository roles)
|
public UserRoleRepository(IDbContextFactory<TenantDBContext> dbContextFactory, IRoleRepository roles)
|
||||||
{
|
{
|
||||||
_dbContextFactory = dbContextFactory;
|
_dbContextFactory = dbContextFactory;
|
||||||
_queryContext = _dbContextFactory.CreateDbContext();
|
|
||||||
_roles = roles;
|
_roles = roles;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<UserRole> GetUserRoles(int siteId)
|
public IEnumerable<UserRole> GetUserRoles(int siteId)
|
||||||
{
|
{
|
||||||
return _queryContext.UserRole
|
using var db = _dbContextFactory.CreateDbContext();
|
||||||
|
return db.UserRole
|
||||||
.Include(item => item.Role) // eager load roles
|
.Include(item => item.Role) // eager load roles
|
||||||
.Include(item => item.User) // eager load users
|
.Include(item => item.User) // eager load users
|
||||||
.Where(item => item.Role.SiteId == siteId || item.Role.SiteId == null);
|
.Where(item => item.Role.SiteId == siteId || item.Role.SiteId == null).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<UserRole> GetUserRoles(int userId, int siteId)
|
public IEnumerable<UserRole> GetUserRoles(int userId, int siteId)
|
||||||
{
|
{
|
||||||
return _queryContext.UserRole.Where(item => item.UserId == userId)
|
using var db = _dbContextFactory.CreateDbContext();
|
||||||
|
return db.UserRole.Where(item => item.UserId == userId)
|
||||||
.Include(item => item.Role) // eager load roles
|
.Include(item => item.Role) // eager load roles
|
||||||
.Include(item => item.User) // eager load users
|
.Include(item => item.User) // eager load users
|
||||||
.Where(item => item.Role.SiteId == siteId || item.Role.SiteId == null || siteId == -1);
|
.Where(item => item.Role.SiteId == siteId || item.Role.SiteId == null || siteId == -1).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserRole AddUserRole(UserRole userRole)
|
public UserRole AddUserRole(UserRole userRole)
|
||||||
|
|
|
@ -9,19 +9,18 @@ namespace Oqtane.Repository
|
||||||
public class VisitorRepository : IVisitorRepository
|
public class VisitorRepository : IVisitorRepository
|
||||||
{
|
{
|
||||||
private readonly IDbContextFactory<TenantDBContext> _dbContextFactory;
|
private readonly IDbContextFactory<TenantDBContext> _dbContextFactory;
|
||||||
private readonly TenantDBContext _queryContext;
|
|
||||||
|
|
||||||
public VisitorRepository(IDbContextFactory<TenantDBContext> dbContextFactory)
|
public VisitorRepository(IDbContextFactory<TenantDBContext> dbContextFactory)
|
||||||
{
|
{
|
||||||
_dbContextFactory = dbContextFactory;
|
_dbContextFactory = dbContextFactory;
|
||||||
_queryContext = _dbContextFactory.CreateDbContext();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Visitor> GetVisitors(int siteId, DateTime fromDate)
|
public IEnumerable<Visitor> GetVisitors(int siteId, DateTime fromDate)
|
||||||
{
|
{
|
||||||
return _queryContext.Visitor.AsNoTracking()
|
using var db = _dbContextFactory.CreateDbContext();
|
||||||
|
return db.Visitor.AsNoTracking()
|
||||||
.Include(item => item.User) // eager load users
|
.Include(item => item.User) // eager load users
|
||||||
.Where(item => item.SiteId == siteId && item.VisitedOn >= fromDate);
|
.Where(item => item.SiteId == siteId && item.VisitedOn >= fromDate).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Visitor AddVisitor(Visitor visitor)
|
public Visitor AddVisitor(Visitor visitor)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user