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

35 lines
1.2 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.Extensions.DependencyInjection;
using PARR.DAL.Services.Interfaces;
namespace PARR.GeneratorTemplates.Services
{
internal class ValidatorService : IValidatorService
{
private readonly IServiceProvider serviceProvider;
public ValidatorService(IServiceProvider serviceProvider)
{
this.serviceProvider = serviceProvider;
}
/// <summary>
/// Проверка, валидны ли поля и связана ли Работа с Приложением
/// </summary>
/// <param name="applicationId"></param>
/// <param name="workId"></param>
/// <returns></returns>
public async Task<bool> IsValidApplicationAndWorksAsync(Guid applicationId, Guid workId)
{
using (var scope = serviceProvider.CreateScope())
{
var service = scope.ServiceProvider.GetService<IApplicationsInWorkService>();
if (service == null)
throw new Exception($"Не найден сервис: {nameof(IApplicationsInWorkService)}");
return await service.GetAsync(applicationId, workId) != null;
}
}
}
}