Skip to content

Commit

Permalink
Merge branch 'develop' into feature/redesign-tiles
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Kulak authored Jan 25, 2022
2 parents 67a749c + 7f31d3f commit a46ea93
Show file tree
Hide file tree
Showing 38 changed files with 59 additions and 126 deletions.
2 changes: 2 additions & 0 deletions common/ASC.Core.Common/EF/Context/AuditTrailContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ public class PostgreSqlAuditTrailContext : AuditTrailContext { }
public class AuditTrailContext : BaseDbContext
{
public DbSet<AuditEvent> AuditEvents { get; set; }
public DbSet<User> Users { get; set; }

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
ModelBuilderWrapper
.From(modelBuilder, Provider)
.AddAuditEvent()
.AddUser()
.AddDbFunction();
}

Expand Down
2 changes: 2 additions & 0 deletions common/ASC.Core.Common/EF/Context/MessagesContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class PostgreSqlMessagesContext : MessagesContext { }
public class MessagesContext : BaseDbContext
{
public DbSet<LoginEvents> LoginEvents { get; set; }
public DbSet<User> Users { get; set; }

protected override Dictionary<Provider, Func<BaseDbContext>> ProviderContext
{
Expand All @@ -31,6 +32,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
ModelBuilderWrapper
.From(modelBuilder, Provider)
.AddLoginEvents()
.AddUser()
.AddDbFunction();
}
}
Expand Down
5 changes: 2 additions & 3 deletions common/ASC.Data.Backup.Core/EF/BackupsContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class BackupsContext : BaseDbContext
{
public DbSet<BackupRecord> Backups { get; set; }
public DbSet<BackupSchedule> Schedules { get; set; }

public DbSet<DbTenant> Tenants { get; set; }
public BackupsContext() { }
public BackupsContext(DbContextOptions<BackupsContext> options)
: base(options)
Expand All @@ -23,8 +23,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
{
ModelBuilderWrapper
.From(modelBuilder, Provider)
.AddDbTenant()
.AddDbTariff();
.AddDbTenant();
}
}

Expand Down
53 changes: 26 additions & 27 deletions common/ASC.Data.Backup.Core/Storage/BackupRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,80 +34,79 @@
using ASC.Core.Tenants;
using ASC.Data.Backup.EF.Context;
using ASC.Data.Backup.EF.Model;

using Microsoft.EntityFrameworkCore;

namespace ASC.Data.Backup.Storage
{
[Scope]
public class BackupRepository : IBackupRepository
{
private Lazy<BackupsContext> LazyBackupsContext { get; }
private BackupsContext BackupContext { get => LazyBackupsContext.Value; }
private Lazy<TenantDbContext> LazyTenantDbContext { get; }
private TenantDbContext TenantDbContext { get => LazyTenantDbContext.Value; }

public BackupRepository(DbContextManager<BackupsContext> backupContext, DbContextManager<TenantDbContext> tenantDbContext)
{
LazyBackupsContext = new Lazy<BackupsContext>(() => backupContext.Value);
LazyTenantDbContext = new Lazy<TenantDbContext>(() => tenantDbContext.Value);
private readonly Lazy<BackupsContext> _backupContext;
public BackupRepository(DbContextManager<BackupsContext> dbContactManager)
{
_backupContext = new Lazy<BackupsContext>(() => dbContactManager.Value);
}

public void SaveBackupRecord(BackupRecord backup)
{
BackupContext.AddOrUpdate(r => r.Backups, backup);
BackupContext.SaveChanges();
_backupContext.Value.AddOrUpdate(r => r.Backups, backup);
_backupContext.Value.SaveChanges();
}

public BackupRecord GetBackupRecord(Guid id)
{
return BackupContext.Backups.SingleOrDefault(b => b.Id == id);
return _backupContext.Value.Backups.Find(id);
}

public BackupRecord GetBackupRecord(string hash, int tenant)
{
return BackupContext.Backups.SingleOrDefault(b => b.Hash == hash && b.TenantId == tenant);
return _backupContext.Value.Backups.AsNoTracking().SingleOrDefault(b => b.Hash == hash && b.TenantId == tenant);
}

public List<BackupRecord> GetExpiredBackupRecords()
{
return BackupContext.Backups.Where(b => b.ExpiresOn != DateTime.MinValue && b.ExpiresOn <= DateTime.UtcNow).ToList();
return _backupContext.Value.Backups.AsNoTracking().Where(b => b.ExpiresOn != DateTime.MinValue && b.ExpiresOn <= DateTime.UtcNow).ToList();
}

public List<BackupRecord> GetScheduledBackupRecords()
{
return BackupContext.Backups.Where(b => b.IsScheduled == true).ToList();
return _backupContext.Value.Backups.AsNoTracking().Where(b => b.IsScheduled == true).ToList();
}

public List<BackupRecord> GetBackupRecordsByTenantId(int tenantId)
{
return BackupContext.Backups.Where(b => b.TenantId == tenantId).ToList();
return _backupContext.Value.Backups.AsNoTracking().Where(b => b.TenantId == tenantId).ToList();
}

public void DeleteBackupRecord(Guid id)
{

var backup = BackupContext.Backups.FirstOrDefault(b => b.Id == id);
var backup = _backupContext.Value.Backups.Find(id);

if (backup != null)
{
BackupContext.Backups.Remove(backup);
BackupContext.SaveChanges();
_backupContext.Value.Backups.Remove(backup);
_backupContext.Value.SaveChanges();
}
}

public void SaveBackupSchedule(BackupSchedule schedule)
{
BackupContext.AddOrUpdate(r => r.Schedules, schedule);
BackupContext.SaveChanges();
_backupContext.Value.AddOrUpdate(r => r.Schedules, schedule);
_backupContext.Value.SaveChanges();
}

public void DeleteBackupSchedule(int tenantId)
{
var shedule = BackupContext.Schedules.Where(s => s.TenantId == tenantId).ToList();
BackupContext.Schedules.RemoveRange(shedule);
BackupContext.SaveChanges();
var shedule = _backupContext.Value.Schedules.Where(s => s.TenantId == tenantId).ToList();

_backupContext.Value.Schedules.RemoveRange(shedule);
_backupContext.Value.SaveChanges();
}

public List<BackupSchedule> GetBackupSchedules()
{
var query = BackupContext.Schedules.Join(TenantDbContext.Tenants,
var query = _backupContext.Value.Schedules.Join(_backupContext.Value.Tenants,
s => s.TenantId,
t => t.Id,
(s, t) => new { schedule = s, tenant = t })
Expand All @@ -119,7 +118,7 @@ public List<BackupSchedule> GetBackupSchedules()

public BackupSchedule GetBackupSchedule(int tenantId)
{
return BackupContext.Schedules.SingleOrDefault(s => s.TenantId == tenantId);
return _backupContext.Value.Schedules.AsNoTracking().SingleOrDefault(s => s.TenantId == tenantId);
}
}
}
7 changes: 2 additions & 5 deletions common/services/ASC.AuditTrail/AuditEventsRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,14 @@ public class AuditEventsRepository
private MessageTarget MessageTarget { get; set; }
private UserFormatter UserFormatter { get; set; }
private Lazy<AuditTrailContext> LazyAuditTrailContext { get; }
private Lazy<UserDbContext> LazyUserDbContext { get; }
private AuditTrailContext AuditTrailContext { get => LazyAuditTrailContext.Value; }
private UserDbContext UserDbContext { get => LazyUserDbContext.Value; }
private AuditActionMapper AuditActionMapper { get; }

public AuditEventsRepository(MessageTarget messageTarget, UserFormatter userFormatter, DbContextManager<AuditTrailContext> dbContextManager, AuditActionMapper auditActionMapper, DbContextManager<UserDbContext> DbContextManager)
public AuditEventsRepository(MessageTarget messageTarget, UserFormatter userFormatter, DbContextManager<AuditTrailContext> dbContextManager, AuditActionMapper auditActionMapper)
{
MessageTarget = messageTarget;
UserFormatter = userFormatter;
LazyAuditTrailContext = new Lazy<AuditTrailContext>(() => dbContextManager.Value );
LazyUserDbContext = new Lazy<UserDbContext>(() => DbContextManager.Value);
AuditActionMapper = auditActionMapper;
}

Expand All @@ -79,7 +76,7 @@ private IEnumerable<AuditEvent> Get(int tenant, DateTime? fromDate, DateTime? to
{
var query =
from q in AuditTrailContext.AuditEvents
from p in UserDbContext.Users.Where(p => q.UserId == p.Id).DefaultIfEmpty()
from p in AuditTrailContext.Users.Where(p => q.UserId == p.Id).DefaultIfEmpty()
where q.TenantId == tenant
orderby q.Date descending
select new Query { AuditEvent = q, User = p };
Expand Down
12 changes: 3 additions & 9 deletions common/services/ASC.AuditTrail/LoginEventsRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,13 @@ namespace ASC.AuditTrail.Data
public class LoginEventsRepository
{
private UserFormatter UserFormatter { get; }
private Lazy<AuditTrailContext> LazyAuditTrailContext { get; }
private AuditTrailContext AuditTrailContext { get => LazyAuditTrailContext.Value; }
private AuditActionMapper AuditActionMapper { get; }
private UserDbContext UserDbContext { get => LazyUserDbContext.Value; }
private Lazy<UserDbContext> LazyUserDbContext { get; }
private MessagesContext MessagesContext { get => LazyMessagesContext.Value; }
private Lazy<MessagesContext> LazyMessagesContext { get; }

public LoginEventsRepository(UserFormatter userFormatter, DbContextManager<AuditTrailContext> dbContextManager, AuditActionMapper auditActionMapper, DbContextManager<UserDbContext> DbContextManager, DbContextManager<MessagesContext> dbMessagesContext)
public LoginEventsRepository(UserFormatter userFormatter, AuditActionMapper auditActionMapper, DbContextManager<MessagesContext> dbMessagesContext)
{
UserFormatter = userFormatter;
LazyAuditTrailContext = new Lazy<AuditTrailContext>(() => dbContextManager.Value);
LazyUserDbContext = new Lazy<UserDbContext>(() => DbContextManager.Value);
AuditActionMapper = auditActionMapper;
LazyMessagesContext = new Lazy<MessagesContext>(() => dbMessagesContext.Value);
}
Expand All @@ -71,7 +65,7 @@ public IEnumerable<LoginEvent> GetLast(int tenant, int chunk)
{
var query =
(from b in MessagesContext.LoginEvents
from p in UserDbContext.Users.Where(p => b.UserId == p.Id).DefaultIfEmpty()
from p in MessagesContext.Users.Where(p => b.UserId == p.Id).DefaultIfEmpty()
where b.TenantId == tenant
orderby b.Date descending
select new Query { LoginEvents = b, User = p })
Expand All @@ -84,7 +78,7 @@ public IEnumerable<LoginEvent> Get(int tenant, DateTime fromDate, DateTime to)
{
var query =
from q in MessagesContext.LoginEvents
from p in UserDbContext.Users.Where(p => q.UserId == p.Id).DefaultIfEmpty()
from p in MessagesContext.Users.Where(p => q.UserId == p.Id).DefaultIfEmpty()
where q.TenantId == tenant
where q.Date >= fromDate
where q.Date <= to
Expand Down
4 changes: 0 additions & 4 deletions products/ASC.CRM/Server/Core/Dao/AbstractDao.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,13 @@ public class AbstractDao

private Lazy<CrmDbContext> LazyCrmDbContext { get; }
public CrmDbContext CrmDbContext { get => LazyCrmDbContext.Value; }
private Lazy<TenantDbContext> LazyTenantDbContext { get; }
public TenantDbContext TenantDbContext { get => LazyTenantDbContext.Value; }
protected readonly SecurityContext _securityContext;
protected readonly ICache _cache;
protected ILog _logger;
protected IMapper _mapper;

public AbstractDao(
DbContextManager<CrmDbContext> dbContextManager,
DbContextManager<TenantDbContext> dbContextManager1,
TenantManager tenantManager,
SecurityContext securityContext,
IOptionsMonitor<ILog> logger,
Expand All @@ -73,7 +70,6 @@ IMapper mapper
_cache = ascCache;

LazyCrmDbContext = new Lazy<CrmDbContext>(() => dbContextManager.Get(CrmConstants.DatabaseId));
LazyTenantDbContext = new Lazy<TenantDbContext>(() => dbContextManager1.Get(CrmConstants.DatabaseId));
TenantID = tenantManager.GetCurrentTenant().TenantId;
_securityContext = securityContext;

Expand Down
4 changes: 1 addition & 3 deletions products/ASC.CRM/Server/Core/Dao/CasesDao.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public class CasesDao : AbstractDao

public CasesDao(
DbContextManager<CrmDbContext> dbContextManager,
DbContextManager<TenantDbContext> dbContextManager1,
TenantManager tenantManager,
SecurityContext securityContext,
CrmSecurity crmSecurity,
Expand All @@ -77,8 +76,7 @@ public CasesDao(
BundleSearch bundleSearch,
IMapper mapper
) :
base(dbContextManager,
dbContextManager1,
base(dbContextManager,
tenantManager,
securityContext,
logger,
Expand Down
2 changes: 0 additions & 2 deletions products/ASC.CRM/Server/Core/Dao/ContactDao.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ public class ContactDao : AbstractDao

public ContactDao(
DbContextManager<CrmDbContext> dbContextManager,
DbContextManager<TenantDbContext> dbContextManager1,
TenantManager tenantManager,
SecurityContext securityContext,
CrmSecurity crmSecurity,
Expand All @@ -83,7 +82,6 @@ public ContactDao(
IMapper mapper
) :
base(dbContextManager,
dbContextManager1,
tenantManager,
securityContext,
logger,
Expand Down
2 changes: 0 additions & 2 deletions products/ASC.CRM/Server/Core/Dao/ContactInfoDao.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public class ContactInfoDao : AbstractDao

public ContactInfoDao(
DbContextManager<CrmDbContext> dbContextManager,
DbContextManager<TenantDbContext> dbContextManager1,
TenantManager tenantManager,
SecurityContext securityContext,
TenantUtil tenantUtil,
Expand All @@ -63,7 +62,6 @@ public ContactInfoDao(
FactoryIndexerContactInfo factoryIndexerContactInfo,
IMapper mapper)
: base(dbContextManager,
dbContextManager1,
tenantManager,
securityContext,
logger,
Expand Down
2 changes: 0 additions & 2 deletions products/ASC.CRM/Server/Core/Dao/CurrencyInfoDao.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,12 @@ namespace ASC.CRM.Core.Dao
public class CurrencyInfoDao : AbstractDao
{
public CurrencyInfoDao(DbContextManager<CrmDbContext> dbContextManager,
DbContextManager<TenantDbContext> dbContextManager1,
TenantManager tenantManager,
SecurityContext securityContext,
IOptionsMonitor<ILog> logger,
ICache ascCache,
IMapper mapper) :
base(dbContextManager,
dbContextManager1,
tenantManager,
securityContext,
logger,
Expand Down
2 changes: 0 additions & 2 deletions products/ASC.CRM/Server/Core/Dao/CurrencyRateDao.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,12 @@ public class CurrencyRateDao : AbstractDao
{
public CurrencyRateDao(
DbContextManager<CrmDbContext> dbContextManager,
DbContextManager<TenantDbContext> dbContextManager1,
TenantManager tenantManager,
SecurityContext securityContext,
IOptionsMonitor<ILog> logger,
ICache ascCache,
IMapper mapper) :
base(dbContextManager,
dbContextManager1,
tenantManager,
securityContext,
logger,
Expand Down
2 changes: 0 additions & 2 deletions products/ASC.CRM/Server/Core/Dao/CustomFieldDao.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ public class CustomFieldDao : AbstractDao

public CustomFieldDao(
DbContextManager<CrmDbContext> dbContextManager,
DbContextManager<TenantDbContext> dbContextManager1,
TenantManager tenantManager,
SecurityContext securityContext,
TenantUtil tenantUtil,
Expand All @@ -68,7 +67,6 @@ public CustomFieldDao(
IMapper mapper
) :
base(dbContextManager,
dbContextManager1,
tenantManager,
securityContext,
logger,
Expand Down
2 changes: 0 additions & 2 deletions products/ASC.CRM/Server/Core/Dao/DealDao.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public class DealDao : AbstractDao
private readonly AuthorizationManager _authorizationManager;

public DealDao(DbContextManager<CrmDbContext> dbContextManager,
DbContextManager<TenantDbContext> dbContextManager1,
TenantManager tenantManager,
SecurityContext securityContext,
CrmSecurity crmSecurity,
Expand All @@ -78,7 +77,6 @@ public DealDao(DbContextManager<CrmDbContext> dbContextManager,
IMapper mapper,
BundleSearch bundleSearch) :
base(dbContextManager,
dbContextManager1,
tenantManager,
securityContext,
logger,
Expand Down
2 changes: 0 additions & 2 deletions products/ASC.CRM/Server/Core/Dao/DealMilestoneDao.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,12 @@ public class DealMilestoneDao : AbstractDao
{

public DealMilestoneDao(DbContextManager<CrmDbContext> dbContextManager,
DbContextManager<TenantDbContext> dbContextManager1,
TenantManager tenantManager,
SecurityContext securityContext,
IOptionsMonitor<ILog> logger,
ICache ascCache,
IMapper mapper) :
base(dbContextManager,
dbContextManager1,
tenantManager,
securityContext,
logger,
Expand Down
2 changes: 0 additions & 2 deletions products/ASC.CRM/Server/Core/Dao/FileDao.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,12 @@ public class FileDao : AbstractDao
private FilesIntegration _filesIntegration;
public FileDao(FilesIntegration filesIntegration,
DbContextManager<CrmDbContext> dbContextManager,
DbContextManager<TenantDbContext> dbContextManager1,
TenantManager tenantManager,
SecurityContext securityContext,
IOptionsMonitor<ILog> logger,
ICache ascCache,
IMapper mapper) :
base(dbContextManager,
dbContextManager1,
tenantManager,
securityContext,
logger,
Expand Down
Loading

0 comments on commit a46ea93

Please sign in to comment.