public async Task <ServerLatestProbesModel> GetLatestProbesAsync() { DateTime?lastCheckedDateTimeUtc = _dbContext.Set <Probe>() .Select(x => (DateTime?)x.CheckedDateTimeUtc) .DefaultIfEmpty() .Max(); if (lastCheckedDateTimeUtc == null) { return(null); } return(new ServerLatestProbesModel { CheckedDateTimeUtc = lastCheckedDateTimeUtc.Value, Servers = await _dbContext.Set <Entities.Server>() .OrderBy(x => x.Host) .Select(x => new ServerModel { Id = x.Id, Host = x.Host, Probes = x.Probes .Where(p => p.CheckedDateTimeUtc == lastCheckedDateTimeUtc) .OrderBy(p => p.Type) .Select(p => new ProbeModel { Id = p.Id, Type = p.Type, Result = p.Result }).ToArray(), Backup = x.Backups .OrderByDescending(b => b.CreatedDateTimeUtc) .Select(b => new BackupModel { BackupDurationTotalSeconds = b.BackupDurationTotalSeconds, LastBackupEndDateTimeUtc = b.LastBackupEndDateTimeUtc, BackupsAmount = b.BackupsAmount, LastBackupSizeBytes = b.LastBackupSizeBytes, IsStatusOk = b.IsStatusOk, BackupDurationCopySeconds = b.BackupDurationCopySeconds, OldestBackupEndDateTimeUtc = b.OldestBackupEndDateTimeUtc, LastBackupStartDateTimeUtc = b.LastBackupStartDateTimeUtc, DiskFreeBytes = b.DiskFreeBytes, DiskUsedBytes = b.DiskUsedBytes }) .FirstOrDefault() }).ToArrayAsync() }); }
public async Task RemoveAsync(Expression <Func <Backup, bool> > predicate) { List <Backup> backups = await _dbContext.Set <Backup>().Where(predicate).ToListAsync(); _dbContext.RemoveRange(backups); await _dbContext.SaveChangesAsync(); }
public async Task RemoveAsync(Expression <Func <Probe, bool> > predicate) { List <Probe> probes = await _dbContext.Set <Probe>().Where(predicate).ToListAsync(); _dbContext.RemoveRange(probes); await _dbContext.SaveChangesAsync(); }
public Task <BackupModel> GetLatestServerBackupAsync(int serverId) { return(_dbContext.Set <Backup>() .Where(x => x.ServerId == serverId) .OrderByDescending(x => x.CreatedDateTimeUtc) .Select(x => new BackupModel { BackupDurationCopySeconds = x.BackupDurationCopySeconds, BackupDurationTotalSeconds = x.BackupDurationTotalSeconds, LastBackupEndDateTimeUtc = x.LastBackupEndDateTimeUtc, BackupsAmount = x.BackupsAmount, IsStatusOk = x.IsStatusOk, LastBackupSizeBytes = x.LastBackupSizeBytes, LastBackupStartDateTimeUtc = x.LastBackupStartDateTimeUtc, OldestBackupEndDateTimeUtc = x.OldestBackupEndDateTimeUtc, DiskFreeBytes = x.DiskFreeBytes, DiskUsedBytes = x.DiskUsedBytes }) .FirstOrDefaultAsync()); }
public Task <Entities.Server[]> GetAllServersAsync() { return(_dbContext.Set <Entities.Server>().ToArrayAsync()); }