38 lines
1.6 KiB
C#
38 lines
1.6 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,
|
|
Value = conf.EsppSchValues.First().EsppSchTypeValue!.Value
|
|
});
|
|
|
|
return response.OrderBy(t => t.Order).ToList();
|
|
}
|
|
}
|
|
}
|