feat(api): переписан метод Update для JobController
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
using FluentValidation;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PARR.API.Contracts.V1.Requests;
|
||||
using PARR.DAL.Models.Job;
|
||||
using PARR.DAL.Services.Interfaces;
|
||||
@@ -27,6 +26,7 @@ namespace PARR.API.Validators
|
||||
this.jobGroupService = jobGroupService;
|
||||
this.jobService = jobService;
|
||||
this.unitFieldService = unitFieldService;
|
||||
|
||||
RuleFor(t => t.Name)
|
||||
.NotNull().NotEmpty();
|
||||
|
||||
@@ -49,17 +49,10 @@ namespace PARR.API.Validators
|
||||
.WithMessage("Неверно заданы параметры фильтров. Внимательнее, пожалуйста!");
|
||||
|
||||
RuleFor(t => t.MinValueRelationships)
|
||||
.MustAsync(async (entity, value, c) => await IsMinValueRelationShipsExist(entity))
|
||||
.WithMessage("Работа с таким минимальным количеством связей уже существует");
|
||||
.GreaterThanOrEqualTo(0);
|
||||
|
||||
RuleFor(t => t.MaxValueRelationships)
|
||||
.GreaterThanOrEqualTo(t => t.MinValueRelationships);
|
||||
|
||||
RuleFor(t => t.MaxValueRelationships)
|
||||
.MustAsync(async (entity, value, c) => await IsMaxValueRelationShipsExist(entity))
|
||||
.WithMessage("Работа с таким максимальным количеством связей уже существует");
|
||||
|
||||
|
||||
}
|
||||
|
||||
private async Task<bool> IsUnitFiltersCorrect(JobRequest entity)
|
||||
@@ -103,21 +96,5 @@ namespace PARR.API.Validators
|
||||
{
|
||||
return await tnkService.GetAsync(entity.TnkId) != null;
|
||||
}
|
||||
|
||||
private async Task<bool> IsMinValueRelationShipsExist(JobRequest entity)
|
||||
{
|
||||
if (!jobGroup?.IsUmbrella == true)
|
||||
return true;
|
||||
|
||||
return await jobService.Get().CountAsync(t => t.GroupId == entity.GroupId && t.MinValueRelationships == entity.MinValueRelationships) == 0;
|
||||
}
|
||||
|
||||
private async Task<bool> IsMaxValueRelationShipsExist(JobRequest entity)
|
||||
{
|
||||
if (!jobGroup?.IsUmbrella == true)
|
||||
return true;
|
||||
|
||||
return await jobService.Get().CountAsync(t => t.GroupId == entity.GroupId && t.MaxValueRelationships == entity.MaxValueRelationships) == 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user