28 lines
1.2 KiB
C#
28 lines
1.2 KiB
C#
using FluentValidation;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using PARR.API.Contracts.V1.Requests;
|
|
using PARR.DAL.Services.Interfaces.Job;
|
|
|
|
namespace PARR.API.Validators
|
|
{
|
|
public class DistributeRequestValidator : AbstractValidator<DistributeRequest>
|
|
{
|
|
public DistributeRequestValidator(IJobGroupService jobGroupService)
|
|
{
|
|
RuleFor(t => t.JobGroupId).NotEmpty().MustAsync(async (entity, value, c) =>
|
|
{
|
|
return await jobGroupService.Get().FirstOrDefaultAsync(t => t.Id == value) != null;
|
|
}).WithMessage("Недопустимое значение");
|
|
|
|
RuleFor(t => t.JobGroupId).NotEmpty().MustAsync(async (entity, value, c) =>
|
|
{
|
|
var jobGroup = await jobGroupService.Get()
|
|
.Include(t => t.DistributionConfig)
|
|
.FirstOrDefaultAsync(t => t.Id == value);
|
|
|
|
return jobGroup != null && jobGroup.IsAutoDistributionEnabled && jobGroup.DistributionConfig != null;
|
|
}).WithMessage("Отсутствуют настройки автораспределения");
|
|
}
|
|
}
|
|
}
|