feat(api,dal): исключения расписаний ЕСПП привязаны к JobGroup, удалены константы из настроек. Кол-во шаблонов в Job считается только used. В JobFieldFilter добавлено поле IsInverse.
This commit is contained in:
@@ -531,6 +531,20 @@
|
||||
public const string GetAll = Base + "/kii-units/";
|
||||
}
|
||||
|
||||
#region Расписание - исключения
|
||||
|
||||
public static class ScheduleExcludeType
|
||||
{
|
||||
public const string GetAll = Base + "/schedule-exclude-types/";
|
||||
}
|
||||
|
||||
public static class ScheduleExcludeTypeCalendar
|
||||
{
|
||||
public const string GetAll = Base + "/schedule-exclude-type-calendars/";
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,6 +23,10 @@
|
||||
|
||||
public DateTimeOffset ReferenceDate { get; set; }
|
||||
|
||||
public Guid ScheduleExcludeTypeId { get; set; }
|
||||
|
||||
public Guid? ScheduleExcludeTypeCalendarId { get; set; }
|
||||
|
||||
//public bool IsAutoDistributionEnabled { get; set; }
|
||||
|
||||
//public bool IsAgent { get; set; }
|
||||
|
||||
@@ -57,6 +57,8 @@
|
||||
|
||||
public string? ValueMask { get; set; }
|
||||
|
||||
public bool IsInverse { get; set; } = false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -42,6 +42,16 @@
|
||||
public int JobsCount { get; set; }
|
||||
public JobGroupScheduleResponse? Schedule { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Расписание
|
||||
/// </summary>
|
||||
public ScheduleExcludeTypeResponse? ScheduleExcludeType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Тип исключения - календарь
|
||||
/// </summary>
|
||||
public ScheduleExcludeTypeCalendarResponse? ScheduleExcludeTypeCalendar { get; set; }
|
||||
|
||||
}
|
||||
|
||||
public class JobGroupScheduleResponse
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
|
||||
public class JobResponse : JobBaseResponse
|
||||
{
|
||||
|
||||
public TnkResponse? Tnk { get; set; }
|
||||
|
||||
public JobGroupBaseResponse? Group { get; set; }
|
||||
@@ -33,7 +32,7 @@
|
||||
|
||||
public JobAutoControlResponse? AutoControl { get; set; }
|
||||
|
||||
#region Статистика
|
||||
#region Статистика Old
|
||||
|
||||
//public TemplateStats? TemplateStatistics { get; set; }
|
||||
|
||||
@@ -64,6 +63,8 @@
|
||||
|
||||
public string? ValueMask { get; set; }
|
||||
|
||||
public bool IsInverse { get; set; }
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
namespace PARR.API.Contracts.V1.Responses
|
||||
{
|
||||
public class ScheduleExcludeTypeCalendarResponse
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
|
||||
public required string Title { get; set; }
|
||||
|
||||
public required string EsppName { get; set; }
|
||||
|
||||
public required string EsppValue { get; set; }
|
||||
|
||||
public required string Code { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
namespace PARR.API.Contracts.V1.Responses
|
||||
{
|
||||
public class ScheduleExcludeTypeResponse
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
|
||||
public required string Title { get; set; }
|
||||
|
||||
public required string EsppName { get; set; }
|
||||
|
||||
public required string EsppValue { get; set; }
|
||||
|
||||
public required string Code { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -50,6 +50,16 @@
|
||||
/// </summary>
|
||||
public EsppScheduleResponse? Schedule { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Тип исклчения
|
||||
/// </summary>
|
||||
public ScheduleExcludeTypeResponse? ScheduleExcludeType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Тип исключения - календарь
|
||||
/// </summary>
|
||||
public ScheduleExcludeTypeCalendarResponse? ScheduleExcludeTypeCalendar { get; set; }
|
||||
|
||||
public int OrderCount { get; set; }
|
||||
|
||||
public TemplateStatusTypeResponse? StatusType { get; set; }
|
||||
|
||||
@@ -24,6 +24,7 @@ using PARR.DAL.Models.Job;
|
||||
using PARR.DAL.Services.Interfaces;
|
||||
using PARR.DAL.Services.Interfaces.Job;
|
||||
using PARR.DAL.Services.Interfaces.Unit;
|
||||
using System.Net;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace PARR.API.Controllers.V1
|
||||
@@ -121,7 +122,8 @@ namespace PARR.API.Controllers.V1
|
||||
|
||||
foreach (var jobResponse in response)
|
||||
{
|
||||
jobResponse.TemplatesCount = await templateService.Get().CountAsync(t => t.JobId == jobResponse.Id);
|
||||
//jobResponse.TemplatesCount = await templateService.Get().CountAsync(t => t.JobId == jobResponse.Id);
|
||||
jobResponse.TemplatesCount = await GetCountTemplatesAsync(jobResponse.Id);
|
||||
}
|
||||
|
||||
var paginationResponse = new PagedResponse<JobResponse>(response, true).GetPaginatedProps(paginationFilter, query);
|
||||
@@ -156,10 +158,10 @@ namespace PARR.API.Controllers.V1
|
||||
|
||||
var response = mapper.Map<JobResponse>(job);
|
||||
|
||||
response.TemplatesCount = await templateService.Get().CountAsync(t => t.JobId == id);
|
||||
response.TemplatesCount = await GetCountTemplatesAsync(id); //await templateService.Get().CountAsync(t => t.JobId == id);
|
||||
|
||||
var statistics = await GetStatisticsAsync(response.Id);
|
||||
BindStatistics(response, statistics);
|
||||
//var statistics = await GetStatisticsAsync(response.Id);
|
||||
//BindStatistics(response, statistics);
|
||||
|
||||
return Ok(new Response<JobResponse>(response, true));
|
||||
}
|
||||
@@ -351,10 +353,11 @@ namespace PARR.API.Controllers.V1
|
||||
.FirstAsync(t => t.Id == orig.Id);
|
||||
|
||||
var response = mapper.Map<JobResponse>(updatedJob);
|
||||
response.TemplatesCount = await templateService.Get().CountAsync(t => t.JobId == id);
|
||||
response.TemplatesCount = await GetCountTemplatesAsync(id); //await templateService.Get().CountAsync(t => t.JobId == id);
|
||||
|
||||
var statistics = await GetStatisticsAsync(response.Id);
|
||||
BindStatistics(response, statistics);
|
||||
//не используется
|
||||
//var statistics = await GetStatisticsAsync(response.Id);
|
||||
//BindStatistics(response, statistics);
|
||||
|
||||
return Ok(new Response<JobResponse>(response, true));
|
||||
}
|
||||
@@ -392,7 +395,9 @@ namespace PARR.API.Controllers.V1
|
||||
|
||||
orig.UnitFilters.Add(newUnitFilter);
|
||||
}
|
||||
/* Писал полноценный апдейт, но Миша сказал что нахрен это - просто все удаляем, а потом создаём заново
|
||||
|
||||
#region old
|
||||
/* Писал полноценный апдейт, но Миша сказал что нахрен это - просто все удаляем, а потом создаём заново... Ох уж этот Миша...
|
||||
//Сразу удаляем UnitFilter которых нет
|
||||
var toDelete = orig.UnitFilters.Where(t => !mappedRequest.UnitFilters.Any(e => e.Id == t.Id));
|
||||
foreach (var item in toDelete)
|
||||
@@ -506,6 +511,8 @@ namespace PARR.API.Controllers.V1
|
||||
#endregion
|
||||
}
|
||||
}*/
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
private static JobRelationshipFilter CreateRelationshipFilter(Guid fieldId, bool isParent, bool isFullMatch, bool isInverse, string valueMask)
|
||||
@@ -636,6 +643,18 @@ namespace PARR.API.Controllers.V1
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Получить кол-во шаблонов в Job
|
||||
/// </summary>
|
||||
/// <param name="jobId"></param>
|
||||
/// <returns></returns>
|
||||
private async Task<int> GetCountTemplatesAsync(Guid jobId)
|
||||
{
|
||||
// Получаем только шаблоны в статусе used
|
||||
return await templateService.Get().CountAsync(t => t.JobId == jobId && t.StatusTypeId == TemplateStatusTypeEnum.Used);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -647,5 +666,4 @@ namespace PARR.API.Controllers.V1
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -72,7 +72,9 @@ namespace PARR.API.Controllers.V1
|
||||
|
||||
IQueryable<JobGroup> query = groupService.Get()
|
||||
.Include(t => t.GroupType)
|
||||
.Include(t => t.GroupingUnitField);
|
||||
.Include(t => t.GroupingUnitField)
|
||||
.Include(t => t.ScheduleExcludeType)
|
||||
.Include(t => t.ScheduleExcludeTypeCalendar);
|
||||
|
||||
query = query.OrderBy(t => t.GroupName);
|
||||
|
||||
@@ -111,6 +113,8 @@ namespace PARR.API.Controllers.V1
|
||||
.Include(t => t.Jobs).ThenInclude(t => t.Tnk)
|
||||
.Include(t => t.GroupType)
|
||||
.Include(t => t.GroupingUnitField)
|
||||
.Include(t => t.ScheduleExcludeType)
|
||||
.Include(t => t.ScheduleExcludeTypeCalendar)
|
||||
.FirstOrDefaultAsync(t => t.Id == id);
|
||||
|
||||
if (jobGroup == null)
|
||||
@@ -148,6 +152,8 @@ namespace PARR.API.Controllers.V1
|
||||
Solution = request.Solution.Trim(),
|
||||
TemplateDuration = request.TemplateDuration.Trim(),
|
||||
ReferenceDate = request.ReferenceDate,
|
||||
ScheduleExcludeTypeId = request.ScheduleExcludeTypeId,
|
||||
ScheduleExcludeTypeCalendarId = request.ScheduleExcludeTypeCalendarId
|
||||
//IsAutoDistributionEnabled = request.IsAutoDistributionEnabled,
|
||||
//IsAgent = request.IsAgent,
|
||||
//AgentName = request.AgentName,
|
||||
@@ -175,6 +181,8 @@ namespace PARR.API.Controllers.V1
|
||||
var createdJobGroup = await groupService.Get().Include(t => t.Jobs).ThenInclude(t => t.Tnk)
|
||||
.Include(t => t.GroupType)
|
||||
.Include(t => t.GroupingUnitField)
|
||||
.Include(t => t.ScheduleExcludeType)
|
||||
.Include(t => t.ScheduleExcludeTypeCalendar)
|
||||
.FirstAsync(t => t.Id == jobGroup.Id);
|
||||
|
||||
var locationUri = uriService.GetUri(ApiRoutes.JobGroup.Get, ApiRoutes.JobGroup.getParam, createdJobGroup.Id);
|
||||
@@ -220,6 +228,8 @@ namespace PARR.API.Controllers.V1
|
||||
orig.Solution = request.Solution.Trim();
|
||||
orig.TemplateDuration = request.TemplateDuration.Trim();
|
||||
orig.ReferenceDate = request.ReferenceDate;
|
||||
orig.ScheduleExcludeTypeId = request.ScheduleExcludeTypeId;
|
||||
orig.ScheduleExcludeTypeCalendarId = request.ScheduleExcludeTypeCalendarId;
|
||||
//orig.IsAutoDistributionEnabled = request.IsAutoDistributionEnabled;
|
||||
//orig.IsAgent = request.IsAgent;
|
||||
//orig.AgentName = request.AgentName;
|
||||
@@ -273,6 +283,8 @@ namespace PARR.API.Controllers.V1
|
||||
.ThenInclude(t => t.Tnk)
|
||||
.Include(t => t.GroupType)
|
||||
.Include(t => t.GroupingUnitField)
|
||||
.Include(t => t.ScheduleExcludeType)
|
||||
.Include(t => t.ScheduleExcludeTypeCalendar)
|
||||
.FirstAsync(t => t.Id == orig.Id);
|
||||
|
||||
var response = mapper.Map<JobGroupResponse>(updatedJobGroup);
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PARR.API.Contracts.V1;
|
||||
using PARR.API.Contracts.V1.Responses;
|
||||
using PARR.API.Contracts.V1.Responses.Base;
|
||||
using PARR.API.Controllers.V1.Base;
|
||||
using PARR.Constants;
|
||||
using PARR.DAL.Services.Interfaces.Schedule;
|
||||
|
||||
namespace PARR.API.Controllers.V1
|
||||
{
|
||||
/// <summary>
|
||||
/// Расписание регламентной работы, исключение - Календарь
|
||||
/// </summary>
|
||||
[Authorize(Roles = ParrRoles.Administrator.Role)]
|
||||
public class ScheduleExcludeTypeCalendarController : BaseApiController
|
||||
{
|
||||
private readonly IMapper mapper;
|
||||
private readonly IScheduleExcludeTypeCalendarService scheduleExcludeTypeCalendarService;
|
||||
|
||||
public ScheduleExcludeTypeCalendarController(
|
||||
IMapper mapper,
|
||||
IScheduleExcludeTypeCalendarService scheduleExcludeTypeCalendarService
|
||||
)
|
||||
{
|
||||
this.mapper = mapper;
|
||||
this.scheduleExcludeTypeCalendarService = scheduleExcludeTypeCalendarService;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Получить список календарей исключений для расписания РР
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet(ApiRoutes.ScheduleExcludeTypeCalendar.GetAll)]
|
||||
public async Task<IActionResult> GetAll()
|
||||
{
|
||||
var query = scheduleExcludeTypeCalendarService.Get().OrderBy(t => t.Title);
|
||||
var calendars = await query.ToListAsync();
|
||||
|
||||
if (!calendars.Any())
|
||||
return NoContent();
|
||||
|
||||
var response = mapper.Map<List<ScheduleExcludeTypeCalendarResponse>>(calendars);
|
||||
|
||||
return Ok(new Response<List<ScheduleExcludeTypeCalendarResponse>>(response, true));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
53
PARR.API/Controllers/V1/ScheduleExcludeTypeController.cs
Normal file
53
PARR.API/Controllers/V1/ScheduleExcludeTypeController.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PARR.API.Contracts.V1;
|
||||
using PARR.API.Contracts.V1.Responses;
|
||||
using PARR.API.Contracts.V1.Responses.Base;
|
||||
using PARR.API.Controllers.V1.Base;
|
||||
using PARR.Constants;
|
||||
using PARR.DAL.Services.Interfaces.Schedule;
|
||||
|
||||
namespace PARR.API.Controllers.V1
|
||||
{
|
||||
/// <summary>
|
||||
/// Расписание регламентной работы - Тип исключения
|
||||
/// </summary>
|
||||
[Authorize(Roles = ParrRoles.Administrator.Role)]
|
||||
public class ScheduleExcludeTypeController : BaseApiController
|
||||
{
|
||||
private readonly IMapper mapper;
|
||||
private readonly IScheduleExcludeTypeService scheduleExcludeTypeService;
|
||||
|
||||
public ScheduleExcludeTypeController(
|
||||
IMapper mapper,
|
||||
IScheduleExcludeTypeService scheduleExcludeTypeService
|
||||
)
|
||||
{
|
||||
this.mapper = mapper;
|
||||
this.scheduleExcludeTypeService = scheduleExcludeTypeService;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Получить список типов исключений для расписания РР
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet(ApiRoutes.ScheduleExcludeType.GetAll)]
|
||||
public async Task<IActionResult> GetAll()
|
||||
{
|
||||
var query = scheduleExcludeTypeService.Get().OrderBy(t => t.Title);
|
||||
var types = await query.ToListAsync();
|
||||
|
||||
if (!types.Any())
|
||||
return NoContent();
|
||||
|
||||
var response = mapper.Map<List<ScheduleExcludeTypeResponse>>(types);
|
||||
|
||||
return Ok(new Response<List<ScheduleExcludeTypeResponse>>(response, true));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -66,6 +66,8 @@ namespace PARR.API.Controllers.V1
|
||||
.Include(t => t.RobotConfigurations).ThenInclude(t => t.RobotStatus)
|
||||
.Include(t => t.Orders)
|
||||
.Include(t => t.StatusType)
|
||||
.Include(t => t.Job).ThenInclude(t => t.Group).ThenInclude(t => t.ScheduleExcludeType)
|
||||
.Include(t => t.Job).ThenInclude(t => t.Group).ThenInclude(t => t.ScheduleExcludeTypeCalendar)
|
||||
.OrderBy(t => t.Name)
|
||||
.AsSplitQuery();
|
||||
|
||||
@@ -125,6 +127,8 @@ namespace PARR.API.Controllers.V1
|
||||
.Include(t => t.RobotConfigurations).ThenInclude(t => t.RobotStatus)
|
||||
.Include(t => t.Orders)
|
||||
.Include(t => t.StatusType)
|
||||
.Include(t => t.Job).ThenInclude(t => t.Group).ThenInclude(t => t.ScheduleExcludeType)
|
||||
.Include(t => t.Job).ThenInclude(t => t.Group).ThenInclude(t => t.ScheduleExcludeTypeCalendar)
|
||||
.AsSplitQuery()
|
||||
.FirstOrDefaultAsync(t => t.Id == id);
|
||||
|
||||
@@ -156,6 +160,8 @@ namespace PARR.API.Controllers.V1
|
||||
.Include(t => t.RobotConfigurations).ThenInclude(t => t.RobotStatus)
|
||||
.Include(t => t.Orders)
|
||||
.Include(t => t.StatusType)
|
||||
.Include(t => t.Job).ThenInclude(t => t.Group).ThenInclude(t => t.ScheduleExcludeType)
|
||||
.Include(t => t.Job).ThenInclude(t => t.Group).ThenInclude(t => t.ScheduleExcludeTypeCalendar)
|
||||
.AsSplitQuery()
|
||||
.FirstOrDefaultAsync(t => t.Id == id);
|
||||
|
||||
@@ -189,6 +195,8 @@ namespace PARR.API.Controllers.V1
|
||||
.Include(t => t.RobotConfigurations).ThenInclude(t => t.RobotStatus)
|
||||
.Include(t => t.Orders)
|
||||
.Include(t => t.StatusType)
|
||||
.Include(t => t.Job).ThenInclude(t => t.Group).ThenInclude(t => t.ScheduleExcludeType)
|
||||
.Include(t => t.Job).ThenInclude(t => t.Group).ThenInclude(t => t.ScheduleExcludeTypeCalendar)
|
||||
.AsSplitQuery()
|
||||
.FirstOrDefaultAsync(t => t.Id == id);
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ using PARR.Common.Domain;
|
||||
using PARR.DAL.DomainModels;
|
||||
using PARR.DAL.Models;
|
||||
using PARR.DAL.Models.Job;
|
||||
using PARR.DAL.Models.Schedule;
|
||||
using PARR.DAL.Models.Unit;
|
||||
|
||||
namespace PARR.API.MappingProfiles
|
||||
@@ -39,7 +40,10 @@ namespace PARR.API.MappingProfiles
|
||||
.ForMember(d => d.LastRun, o => o.MapFrom(s => s.LastRun))
|
||||
.ForMember(d => d.OrderCount, o => o.MapFrom(s => s.Orders.Count()))
|
||||
.ForMember(d => d.IsAutoDistributionEnabled, o => o.MapFrom(s => s.Job!.Group!.IsAutoDistributionEnabled))
|
||||
.ForMember(d => d.StatusType, o => o.MapFrom(s => s.StatusType));
|
||||
.ForMember(d => d.StatusType, o => o.MapFrom(s => s.StatusType))
|
||||
.ForMember(d => d.ScheduleExcludeType, o => o.MapFrom(s => s.Job!.Group!.ScheduleExcludeType))
|
||||
.ForMember(d => d.ScheduleExcludeTypeCalendar, o => o.MapFrom(s => s.Job!.Group!.ScheduleExcludeTypeCalendar))
|
||||
;
|
||||
// === Template ===
|
||||
|
||||
|
||||
@@ -353,6 +357,7 @@ namespace PARR.API.MappingProfiles
|
||||
#endregion
|
||||
|
||||
#region JobGroup
|
||||
|
||||
CreateMap<JobGroup, JobGroupBaseResponse>()
|
||||
.Include<JobGroup, JobGroupResponse>()
|
||||
.ForMember(d => d.GroupType, o => o.MapFrom(s => s.GroupType))
|
||||
@@ -361,9 +366,23 @@ namespace PARR.API.MappingProfiles
|
||||
CreateMap<JobGroup, JobGroupBaseResponse>()
|
||||
.ForMember(d => d.Name, o => o.MapFrom(s => s.GroupName));
|
||||
|
||||
CreateMap<JobGroup, JobGroupResponse>();
|
||||
CreateMap<JobGroup, JobGroupResponse>()
|
||||
.ForMember(d => d.ScheduleExcludeType, o => o.MapFrom(s => s.ScheduleExcludeType))
|
||||
.ForMember(d => d.ScheduleExcludeTypeCalendar, o => o.MapFrom(s => s.ScheduleExcludeTypeCalendar));
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region ScheduleExcludeTypeCalendarResponse
|
||||
|
||||
CreateMap<ScheduleExcludeTypeCalendar, ScheduleExcludeTypeCalendarResponse>();
|
||||
|
||||
#endregion
|
||||
|
||||
#region ScheduleExcludeTypeResponse
|
||||
|
||||
CreateMap<ScheduleExcludeType, ScheduleExcludeTypeResponse>();
|
||||
|
||||
#endregion
|
||||
|
||||
#region JobGroupType
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
using FluentValidation;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using PARR.API.Contracts.V1.Requests;
|
||||
using PARR.DAL.Contracts;
|
||||
using PARR.DAL.Services.Interfaces.Job;
|
||||
using PARR.DAL.Services.Interfaces.Schedule;
|
||||
using PARR.DAL.Services.Interfaces.Unit;
|
||||
|
||||
namespace PARR.API.Validators
|
||||
@@ -12,7 +12,9 @@ namespace PARR.API.Validators
|
||||
{
|
||||
public JobGroupValidator(
|
||||
IJobGroupTypeService jobGroupTypeService,
|
||||
IUnitFieldService unitFieldService
|
||||
IUnitFieldService unitFieldService,
|
||||
IScheduleExcludeTypeService scheduleExcludeTypeService,
|
||||
IScheduleExcludeTypeCalendarService scheduleExcludeTypeCalendarService
|
||||
)
|
||||
{
|
||||
RuleFor(t => t.Name)
|
||||
@@ -60,6 +62,36 @@ namespace PARR.API.Validators
|
||||
return true;
|
||||
})
|
||||
.WithMessage("Не указано поле для группировки");
|
||||
|
||||
RuleFor(t => t.ScheduleExcludeTypeId)
|
||||
.NotNull()
|
||||
.NotEmpty()
|
||||
.MustAsync(async (entity, value, c) => await scheduleExcludeTypeService.GetAsync(value) != null)
|
||||
.WithMessage("Некорректное значение");
|
||||
|
||||
RuleFor(t => t.ScheduleExcludeTypeCalendarId)
|
||||
.MustAsync(async (entity, value, c) =>
|
||||
{
|
||||
// Если выбрано "Нет исключений", то это поле должно быть пустое, иначе, должно быть валидное значение
|
||||
var type = await scheduleExcludeTypeService.GetAsync(entity.ScheduleExcludeTypeId);
|
||||
if (type == null)
|
||||
return false;
|
||||
|
||||
if (type.Code == ScheduleExcludeTypeEnum.None.ToString())
|
||||
{
|
||||
// ScheduleExcludeTypeCalendarId должно быть null
|
||||
return value == null;
|
||||
}
|
||||
|
||||
// Тип любой кроме "Нет исключений", значение обязательно
|
||||
if (!value.HasValue)
|
||||
return false;
|
||||
|
||||
return await scheduleExcludeTypeCalendarService.GetAsync(value.Value) != null;
|
||||
})
|
||||
.WithMessage("Некорректное значение");
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user