2023-06-01 12:30:38 +10:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
|
using PARR.DAL.Context;
|
2023-08-14 15:24:57 +10:00
|
|
|
|
using PARR.DAL.Models;
|
2026-04-14 09:56:31 +10:00
|
|
|
|
using PARR.DAL.Repositories.Base;
|
2023-06-01 12:30:38 +10:00
|
|
|
|
using PARR.DAL.Services.Interfaces;
|
|
|
|
|
|
|
|
|
|
|
|
namespace PARR.DAL.Services.Implementations
|
|
|
|
|
|
{
|
2026-04-14 09:56:31 +10:00
|
|
|
|
internal class HostService : BaseRepository<Host>, IHostService
|
2023-06-01 12:30:38 +10:00
|
|
|
|
{
|
2026-04-14 09:56:31 +10:00
|
|
|
|
public HostService(DataContext dataContext, ILogger<HostService> logger) : base(logger, dataContext) { }
|
2023-06-05 16:28:36 +10:00
|
|
|
|
|
2024-04-18 10:18:14 +10:00
|
|
|
|
|
|
|
|
|
|
public async Task<Host?> GetHostWithAppsByIpAsync(string ip)
|
2023-06-05 16:28:36 +10:00
|
|
|
|
{
|
2024-04-18 10:18:14 +10:00
|
|
|
|
return await GetHostWithIncludeApps()
|
|
|
|
|
|
.AsSplitQuery()
|
|
|
|
|
|
.FirstOrDefaultAsync(h => h.IP == ip);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-06-13 15:04:47 +10:00
|
|
|
|
|
2024-04-18 10:18:14 +10:00
|
|
|
|
public async Task<Host?> GetHostWithAppsByEkAsync(string ek)
|
|
|
|
|
|
{
|
|
|
|
|
|
return await GetHostWithIncludeApps()
|
2023-06-20 12:29:58 +10:00
|
|
|
|
.AsSplitQuery()
|
2024-04-18 10:18:14 +10:00
|
|
|
|
.FirstOrDefaultAsync(h => h.Ek.ToLower() == ek.ToLower());
|
2023-06-05 16:28:36 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-04-18 10:18:14 +10:00
|
|
|
|
|
|
|
|
|
|
private IQueryable<Host> GetHostWithIncludeApps()
|
2023-12-01 16:41:37 +10:00
|
|
|
|
{
|
2024-06-26 11:48:19 +10:00
|
|
|
|
return EntitySet
|
|
|
|
|
|
.Include(t => t.ApplicationsInHosts)
|
|
|
|
|
|
.ThenInclude(a => a.Application)
|
|
|
|
|
|
.ThenInclude(t => t!.ApplicationType)
|
|
|
|
|
|
.Include(t => t.WorkGroup);
|
2023-12-01 16:41:37 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-06-05 16:28:36 +10:00
|
|
|
|
|
2024-04-18 10:18:14 +10:00
|
|
|
|
public async Task<Host?> GetByIpAsync(string ip)
|
|
|
|
|
|
{
|
|
|
|
|
|
return await EntitySet.FirstOrDefaultAsync(t => t.IP == ip);
|
|
|
|
|
|
}
|
2023-06-05 16:28:36 +10:00
|
|
|
|
|
|
|
|
|
|
|
2024-04-18 10:18:14 +10:00
|
|
|
|
public async Task<Host?> GetByEkAsync(string ek)
|
|
|
|
|
|
{
|
|
|
|
|
|
return await EntitySet.FirstOrDefaultAsync(t => t.Ek.ToLower() == ek.ToLower());
|
|
|
|
|
|
}
|
2023-06-05 16:28:36 +10:00
|
|
|
|
|
|
|
|
|
|
|
2023-06-01 12:30:38 +10:00
|
|
|
|
}
|
|
|
|
|
|
}
|