2020-10-24 23:23:22 +02:00
|
|
|
|
using AutoMapper;
|
2020-11-01 12:25:45 +01:00
|
|
|
|
using Birdmap.API.DTOs;
|
2020-10-24 23:23:22 +02:00
|
|
|
|
using Birdmap.DAL.Entities;
|
2020-11-01 12:25:45 +01:00
|
|
|
|
using System;
|
2020-10-24 23:23:22 +02:00
|
|
|
|
|
|
|
|
|
namespace Birdmap.API.MapperProfiles
|
|
|
|
|
{
|
|
|
|
|
public class BirdmapProfile : Profile
|
|
|
|
|
{
|
|
|
|
|
public BirdmapProfile()
|
|
|
|
|
{
|
2020-11-01 12:25:45 +01:00
|
|
|
|
CreateMap<Uri, string>().ConvertUsing<UriToStringConverter>();
|
|
|
|
|
CreateMap<string, Uri>().ConvertUsing<UriToStringConverter>();
|
|
|
|
|
|
|
|
|
|
CreateMap<User, AuthenticateResponse>()
|
2020-10-25 16:52:39 +01:00
|
|
|
|
.ForMember(m => m.Username, opt => opt.MapFrom(m => m.Name))
|
|
|
|
|
.ForMember(m => m.UserRole, opt => opt.MapFrom(m => m.Role))
|
|
|
|
|
.ReverseMap();
|
2020-11-01 12:25:45 +01:00
|
|
|
|
|
|
|
|
|
CreateMap<Service, ServiceRequest>()
|
|
|
|
|
.ReverseMap();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class UriToStringConverter : ITypeConverter<Uri, string>, ITypeConverter<string, Uri>
|
|
|
|
|
{
|
|
|
|
|
public string Convert(Uri source, string destination, ResolutionContext context)
|
|
|
|
|
{
|
|
|
|
|
destination = source.ToString();
|
|
|
|
|
return destination;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Uri Convert(string source, Uri destination, ResolutionContext context)
|
|
|
|
|
{
|
|
|
|
|
Uri.TryCreate(source, UriKind.Absolute, out destination);
|
|
|
|
|
return destination;
|
|
|
|
|
}
|
2020-10-24 23:23:22 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|