144 lines
4.6 KiB
C#
144 lines
4.6 KiB
C#
using Microsoft.EntityFrameworkCore;
|
||
using Microsoft.Extensions.Logging;
|
||
using PARR.DAL.Context;
|
||
using PARR.DAL.DomainModels;
|
||
using PARR.DAL.Models.V1;
|
||
using PARR.DAL.Services.Abstracts;
|
||
using PARR.DAL.Services.Interfaces.V1;
|
||
|
||
namespace PARR.DAL.Services.Implementations.V1
|
||
{
|
||
internal class V1_HostService : BaseService<V1_Host>, V1_IHostService
|
||
{
|
||
private readonly DataContext dataContext;
|
||
private readonly ILogger<V1_HostService> logger;
|
||
|
||
protected override DbSet<V1_Host> EntitySet => dataContext.V1_Hosts;
|
||
|
||
protected override DataContext EntitiContext => dataContext;
|
||
public V1_HostService(DataContext dataContext, ILogger<V1_HostService> logger) : base(logger)
|
||
{
|
||
this.dataContext = dataContext;
|
||
this.logger = logger;
|
||
}
|
||
|
||
public async Task<V1_Host?> GetHostWithAppsAsync(string IP, string RegionalEK)
|
||
{
|
||
|
||
//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)
|
||
.AsSplitQuery()
|
||
.FirstOrDefaultAsync(h => h.IP == IP && h.RegionalEK == RegionalEK);
|
||
}
|
||
|
||
public async Task<V1_Host?> GetHostWithAppsAsync(string IP, string linkEK, string regionalEK)
|
||
{
|
||
return await EntitySet
|
||
.Include(t => t.ApplicationsInHosts).ThenInclude(a => a.Application).ThenInclude(t => t.ApplicationType)
|
||
.AsSplitQuery()
|
||
.FirstOrDefaultAsync(h => h.IP == IP && h.LinkEK == linkEK && h.RegionalEK == regionalEK);
|
||
}
|
||
|
||
|
||
public async Task<V1_Host?> GetHostByIPAndRegionalEKAsync(string IP, string RegionalEK)
|
||
{
|
||
return await EntitySet.FirstOrDefaultAsync(h => h.IP == IP && h.RegionalEK == RegionalEK);
|
||
}
|
||
|
||
public Task<V1_Host?> GetAsync(Guid id)
|
||
{
|
||
throw new NotImplementedException();
|
||
}
|
||
|
||
public IQueryable<V1_Host> Get()
|
||
{
|
||
throw new NotImplementedException();
|
||
}
|
||
|
||
public IQueryable<V1_Host> GetPage(IQueryable<V1_Host> query, PaginationFilter paginationFilter)
|
||
{
|
||
throw new NotImplementedException();
|
||
}
|
||
|
||
public Task<bool> CreateAsync(V1_Host obj)
|
||
{
|
||
throw new NotImplementedException();
|
||
}
|
||
|
||
public Task<bool> AddRangeAsync(List<V1_Host> objs)
|
||
{
|
||
throw new NotImplementedException();
|
||
}
|
||
|
||
public Task<bool> DeleteAsync(Guid id)
|
||
{
|
||
throw new NotImplementedException();
|
||
}
|
||
|
||
public bool Delete(V1_Host obj)
|
||
{
|
||
throw new NotImplementedException();
|
||
}
|
||
|
||
public Task<bool> CommitAsync()
|
||
{
|
||
throw new NotImplementedException();
|
||
}
|
||
|
||
//public async Task<Host?> GetHostByRegionalEKAsync(string RegionalEK)И
|
||
//{
|
||
// 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;
|
||
// }
|
||
|
||
//}
|
||
|
||
}
|
||
}
|