53 lines
2.2 KiB
C#
53 lines
2.2 KiB
C#
using System.Linq;
|
|
using AutoMapper;
|
|
using AutoMapper.Internal;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using OD.WebApplication.Context;
|
|
using OD.WebApplication.Models;
|
|
|
|
namespace OD.WebApplication.Profiles
|
|
{
|
|
public class OriginToDestinationProfile : Profile
|
|
{
|
|
public OriginToDestinationProfile()
|
|
{
|
|
CreateMap<OriginDataModel, DestinationDataModel>()
|
|
.ForMember(dest => dest.Category, opt => opt.MapFrom(src=> ResolveCategory(src)))
|
|
.ForMember(dest => dest.Brand, opt => opt.MapFrom(src => src.Manufacturer))
|
|
.ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.Name))
|
|
.ForMember(dest => dest.AlternateCode, opt => opt.MapFrom(src => ResolveAlternateCode(src)))
|
|
.ForMember(dest => dest.StorePriceWithVAT, opt => opt.MapFrom(src => ResolveAddVAT(src.PriceListingWithoutVAT)))
|
|
.ForMember(dest => dest.OnlinePriceWithVAT, opt => opt.MapFrom(src => ResolveAddVAT(src.PricePublicWithoutVAT)))
|
|
.ForMember(dest => dest.OnlineValueWihtVAT, opt => opt.MapFrom(src => ResolveAddVAT(src.PriceRecommendedWithoutVAT)));
|
|
}
|
|
|
|
private static string ResolveCategory(OriginDataModel src)
|
|
{
|
|
var categories = src.Categories.Split(',').ToList();
|
|
categories = categories.Select(del => del.Trim()).ToList();
|
|
foreach (var category in categories)
|
|
{
|
|
if (ApplicationContextHelper.BusinessApplicationCategories.Any(x =>
|
|
x.Contains(category) || category.Contains(x)))
|
|
{
|
|
return ApplicationContextHelper.BusinessApplicationCategories.First(x =>
|
|
x.Contains(category) || category.Contains(x));
|
|
}
|
|
}
|
|
|
|
return "OTRO";
|
|
}
|
|
|
|
private static string ResolveAlternateCode(OriginDataModel src)
|
|
{
|
|
return src.ShortDesc.ToUpper().Replace(" ", "");
|
|
}
|
|
|
|
private static int ResolveAddVAT(decimal input)
|
|
{
|
|
const decimal vat = 0.21m;
|
|
var result = decimal.Round(input * vat + input);
|
|
return decimal.ToInt32(result);
|
|
}
|
|
}
|
|
} |