Files
parr_api/PARR.TemplateActivator/Services/ValidatorService.cs

43 lines
1.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using PARR.Constants;
using PARR.DAL.Services.Interfaces;
namespace PARR.TemplateActivator;
internal class ValidatorService : IValidatorService
{
private readonly IServiceProvider serviceProvider;
private readonly ILogger<ValidatorService> logger;
public ValidatorService(IServiceProvider serviceProvider,
ILogger<ValidatorService> logger
)
{
this.serviceProvider = serviceProvider;
this.logger = logger;
}
public async Task<bool> IsValidApplicationInWorkAsync(Guid applicationInWorkId)
{
using (var scope = serviceProvider.CreateScope())
{
var service = scope.ServiceProvider.GetService<IApplicationsInWorkService>();
if (service == null)
throw new Exception($"Не найден сервис: {nameof(IApplicationsInWorkService)}");
var appInWork = await service.Get()
.FirstOrDefaultAsync(t => t.Id == applicationInWorkId);
if (appInWork == null)
{
logger.LogError($"Не найдена регалментная работа {nameof(applicationInWorkId)}: {applicationInWorkId}");
return false;
}
return true;
}
}
}