Added Product URL Resolver
This commit is contained in:
parent
263aa50631
commit
e57e87ad9e
@ -10,7 +10,8 @@ namespace API.Helpers
|
|||||||
{
|
{
|
||||||
CreateMap<Product, ProductToReturnDto>()
|
CreateMap<Product, ProductToReturnDto>()
|
||||||
.ForMember(d => d.ProductBrand, o => o.MapFrom(s => s.ProductBrand.Name))
|
.ForMember(d => d.ProductBrand, o => o.MapFrom(s => s.ProductBrand.Name))
|
||||||
.ForMember(d => d.ProductType, o => o.MapFrom(s => s.ProductType.Name));
|
.ForMember(d => d.ProductType, o => o.MapFrom(s => s.ProductType.Name))
|
||||||
|
.ForMember(d => d.PictureUrl, o => o.MapFrom<ProductUrlResolver>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
25
API/Helpers/ProductUrlResolver.cs
Normal file
25
API/Helpers/ProductUrlResolver.cs
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
using API.Dtos;
|
||||||
|
using AutoMapper;
|
||||||
|
using Core.Entities;
|
||||||
|
|
||||||
|
namespace API.Helpers
|
||||||
|
{
|
||||||
|
public class ProductUrlResolver : IValueResolver<Product, ProductToReturnDto, string>
|
||||||
|
{
|
||||||
|
private readonly IConfiguration _config;
|
||||||
|
public ProductUrlResolver(IConfiguration config)
|
||||||
|
{
|
||||||
|
_config = config;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Resolve(Product source, ProductToReturnDto destination, string destMember, ResolutionContext context)
|
||||||
|
{
|
||||||
|
if(!string.IsNullOrEmpty(source.PictureUrl))
|
||||||
|
{
|
||||||
|
return _config["ApiUrl"] + source.PictureUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -7,5 +7,6 @@
|
|||||||
},
|
},
|
||||||
"ConnectionStrings": {
|
"ConnectionStrings": {
|
||||||
"DefaultConnection": "Data source=ecommerce.db"
|
"DefaultConnection": "Data source=ecommerce.db"
|
||||||
}
|
},
|
||||||
|
"ApiUrl": "https://localhost:5001/"
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user