Files
parr_api/PARR.API/MappingProfiles/Resolvers/RobotTaskScheduleSchResolver.cs

39 lines
1.7 KiB
C#

using AutoMapper;
using PARR.API.Contracts.V1.Responses;
using PARR.DAL.Models;
using PARR.DAL.Services.Interfaces;
namespace PARR.API.MappingProfiles.Resolvers
{
public class RobotTaskScheduleSchResolver : IValueResolver<RobotConfiguration, RobotTaskScheduleResponse, List<RobotTaskScheduleSchResponse>?>
{
private readonly IEsppSchTypeConfigService esppConfigService;
public RobotTaskScheduleSchResolver(IEsppSchTypeConfigService esppConfigService)
{
this.esppConfigService = esppConfigService;
}
public List<RobotTaskScheduleSchResponse>? Resolve(RobotConfiguration source, RobotTaskScheduleResponse destination, List<RobotTaskScheduleSchResponse>? destMember, ResolutionContext context)
{
//todo: может вынести эту логику в сервис?
var appInWorksId = source.Template!.ApplicationInWorkId;
var configs = esppConfigService.GetWithSchIncludes()
.Where(t => t.EsppSchValues.Any(x => x.ApplicationsInWorkId == appInWorksId))
.ToList();
var response = configs.Select(conf =>
new RobotTaskScheduleSchResponse
{
Order = conf.Order,
Type = conf.EsppSchType!.Name,
TypeCode = conf.EsppSchType!.Id,
Value = conf.EsppSchValues.First().EsppSchTypeValue!.Value
});
return response.OrderBy(t => t.Order).ToList();
}
}
}