Initial commit
This commit is contained in:
13
GerstITS.Examples.Logic/Example/Contracts/Example.cs
Normal file
13
GerstITS.Examples.Logic/Example/Contracts/Example.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
namespace GerstITS.Examples.Logic.Example
|
||||
{
|
||||
public class Example
|
||||
{
|
||||
#region Properties
|
||||
|
||||
public string FirstName { get; set; }
|
||||
public string LastName { get; set; }
|
||||
public string Description { get; set; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace GerstITS.Examples.Logic.Example
|
||||
{
|
||||
public interface IExampleProvider
|
||||
{
|
||||
Example GetById(int id);
|
||||
Example GetById_v1_1(int id);
|
||||
}
|
||||
}
|
||||
51
GerstITS.Examples.Logic/Example/ExampleProvider.cs
Normal file
51
GerstITS.Examples.Logic/Example/ExampleProvider.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
19
GerstITS.Examples.Logic/Example/Mappings/IntegerMapping.cs
Normal file
19
GerstITS.Examples.Logic/Example/Mappings/IntegerMapping.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using AutoMapper;
|
||||
|
||||
namespace GerstITS.Examples.Logic.Example
|
||||
{
|
||||
internal sealed class IntegerMapping : Profile
|
||||
{
|
||||
#region Construtcors
|
||||
|
||||
public IntegerMapping()
|
||||
{
|
||||
CreateMap<int, Example>()
|
||||
.ForMember(x => x.FirstName, m => m.MapFrom((s,t) => $"First Name {s}"))
|
||||
.ForMember(x => x.LastName, m => m.MapFrom((s,t) => $"Last Name {s}"))
|
||||
.ForMember(x => x.Description, m => m.MapFrom((s,t) => $"Useful description for id '{s}'"));
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user