51 lines
1.0 KiB
C#
51 lines
1.0 KiB
C#
using AutoMapper;
|
|
using GerstITS.Data;
|
|
|
|
namespace GerstITS.Examples.Logic.Example
|
|
{
|
|
internal sealed class ExampleProvider : IExampleProvider
|
|
{
|
|
#region Fields
|
|
|
|
private readonly IMapper _mapper;
|
|
|
|
#endregion
|
|
|
|
#region Constructors
|
|
|
|
public ExampleProvider(IMapper mapper)
|
|
{
|
|
_mapper = mapper;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region IExampleProvider
|
|
|
|
public Example GetById(int id)
|
|
{
|
|
ThrowsAnExceptionIfEntityIsNotFound(id);
|
|
|
|
return _mapper.Map<Example>(id);
|
|
}
|
|
|
|
public Example GetById_v1_1(int id)
|
|
{
|
|
ThrowsAnExceptionIfEntityIsNotFound(id);
|
|
|
|
return _mapper.Map<Example>(id);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Methods
|
|
|
|
private static void ThrowsAnExceptionIfEntityIsNotFound(int id)
|
|
{
|
|
if (id % 2 == 0)
|
|
throw new EntityNotFoundException($"Example mit der Id '{id}' nicht gefunden.");
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
} |