Files
parr_api/PARR.DAL/Services/Implementations/HostService.cs

89 lines
2.9 KiB
C#
Raw Normal View History

2023-06-01 12:30:38 +10:00
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using PARR.DAL.Context;
using PARR.DAL.Models;
2023-06-01 12:30:38 +10:00
using PARR.DAL.Services.Abstracts;
using PARR.DAL.Services.Interfaces;
namespace PARR.DAL.Services.Implementations
{
internal class HostService : BaseService<Host>, IHostService
2023-06-01 12:30:38 +10:00
{
private readonly DataContext dataContext;
private readonly ILogger<HostService> logger;
protected override DbSet<Host> EntitySet => dataContext.Hosts;
2023-06-01 12:30:38 +10:00
protected override DataContext EntitiContext => dataContext;
public HostService(DataContext dataContext, ILogger<HostService> logger) : base(logger)
{
this.dataContext = dataContext;
this.logger = logger;
}
2023-06-05 16:28:36 +10:00
public async Task<Host?> GetHostWithAppsAsync(string IP)
2023-06-05 16:28:36 +10:00
{
//try
//{
// var host = await EntitySet.FirstAsync(h => h.IP == IP && h.RegionalEK == RegionalEK);
// return host;
//}
//catch
//{
// logger.LogInformation($"Не найден узел с IP адресом {IP} и региональным ЭК {RegionalEK}");
// return null;
//}
return await EntitySet
.Include(t => t.ApplicationsInHosts).ThenInclude(a => a.Application).ThenInclude(t => t.ApplicationType)
2023-06-20 12:29:58 +10:00
.AsSplitQuery()
.FirstOrDefaultAsync(h => h.IP == IP);
2023-06-05 16:28:36 +10:00
}
//public async Task<Host?> GetHostByRegionalEKAsync(string RegionalEK)И
2023-06-05 16:28:36 +10:00
//{
// try
// {
// var host = await EntitySet.FirstAsync(h => h.RegionalEK == RegionalEK);
// return host;
// }
// catch
// {
// logger.LogInformation($"Не найден узел с региональным ЭК {RegionalEK}");
// return null;
// }
//}
//public async Task<bool> UpdateAsync(Host host)
//{
// var orig = await EntitySet.FirstAsync(h => h.IP == host.IP);
// if (orig == null)
// return false;
// orig.DateModified = DateTimeOffset.UtcNow;
// orig.HostName = host.HostName;
// orig.RegionalEK = host.RegionalEK;
// orig.LinkEK = host.LinkEK;
// orig.Status = host.Status;
// orig.WorkGroup = host.WorkGroup;
// orig.Responsible = host.Responsible;
// orig.OS = host.OS;
// orig.DB = host.DB;
// orig.APP = host.APP;
// if (!await CommitAsync())
// {
// logger.LogError($"Ошибка обновления узла {host.IP}");
// return false;
// }
// else
// {
// logger.LogInformation($"Обновлен узел {host.IP}");
// return true;
// }
//}
2023-06-01 12:30:38 +10:00
}
}