Files
parr_api/PARR.API/MappingProfiles/Resolvers/HistoryInitiatorParrComponentResolver.cs
2024-10-08 13:53:57 +10:00

29 lines
1.1 KiB
C#

using AutoMapper;
using Microsoft.EntityFrameworkCore;
using PARR.API.Contracts.V1.Responses;
using PARR.Common.Domain;
using PARR.DAL.Services.Interfaces;
namespace PARR.API.MappingProfiles.Resolvers
{
public class HistoryInitiatorParrComponentResolver : IValueResolver<IHistoryInitiator, HistoryInitiatorResponse, ParrComponentResponse?>
{
private readonly IParrComponentService parrComponentService;
public HistoryInitiatorParrComponentResolver(IParrComponentService parrComponentService)
{
this.parrComponentService = parrComponentService;
}
public ParrComponentResponse? Resolve(IHistoryInitiator source, HistoryInitiatorResponse destination, ParrComponentResponse? destMember, ResolutionContext context)
{
var component = parrComponentService.Get().FirstOrDefaultAsync(t => t.Id == source.InitiatorParrComponentId).GetAwaiter().GetResult();
if (component == null)
return null;
return new ParrComponentResponse { Description = component.Description, Name = component.Name, Id = (int)component.Id };
}
}
}