using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using PARR.DAL.Context; using PARR.DAL.Models; using PARR.DAL.Services.Abstracts; using PARR.DAL.Services.Interfaces; namespace PARR.DAL.Services.Implementations { internal class HostService : BaseService, IHostService { private readonly DataContext dataContext; private readonly ILogger logger; protected override DbSet EntitySet => dataContext.Hosts; protected override DataContext EntitiContext => dataContext; public HostService(DataContext dataContext, ILogger logger) : base(logger) { this.dataContext = dataContext; this.logger = logger; } public async Task GetHostWithAppsAsync(string IP) { //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); } //public async Task GetHostByRegionalEKAsync(string RegionalEK)И //{ // try // { // var host = await EntitySet.FirstAsync(h => h.RegionalEK == RegionalEK); // return host; // } // catch // { // logger.LogInformation($"Не найден узел с региональным ЭК {RegionalEK}"); // return null; // } //} //public async Task 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; // } //} } }