Files
parr_api/PARR.API/Validators/DistributeRequestValidator.cs

28 lines
1.2 KiB
C#
Raw Permalink Normal View History

2024-07-05 12:42:01 +10:00
using FluentValidation;
using Microsoft.EntityFrameworkCore;
2024-07-05 12:42:01 +10:00
using PARR.API.Contracts.V1.Requests;
using PARR.Core.Repositories.Interfaces.JobGroupRepositories;
2024-07-05 12:42:01 +10:00
namespace PARR.API.Validators
{
public class DistributeRequestValidator : AbstractValidator<DistributeRequest>
{
public DistributeRequestValidator(IJobGroupRepository jobGroupService)
2024-07-05 12:42:01 +10:00
{
RuleFor(t => t.JobGroupId).NotEmpty().MustAsync(async (entity, value, c) =>
{
return await jobGroupService.Get().FirstOrDefaultAsync(t => t.Id == value) != null;
}).WithMessage("Недопустимое значение");
2024-07-05 12:42:01 +10:00
RuleFor(t => t.JobGroupId).NotEmpty().MustAsync(async (entity, value, c) =>
2024-07-05 12:42:01 +10:00
{
var jobGroup = await jobGroupService.Get()
.Include(t => t.DistributionConfig)
.FirstOrDefaultAsync(t => t.Id == value);
2024-07-05 12:42:01 +10:00
return jobGroup != null && jobGroup.IsAutoDistributionEnabled && jobGroup.DistributionConfig != null;
}).WithMessage("Отсутствуют настройки автораспределения");
2024-07-05 12:42:01 +10:00
}
}
}