Exemplo n.º 1
0
        protected ProductMapperProfile(string profileName)
            : base(profileName)
        {
            // TODO: fix workingLanguageId
            CreateMap <Product, ProductDto>()
            .ForMember(x => x.AngularComponentCode, m => m.ResolveUsing(x => x.Route?.AngularComponent?.Code))
            .ForMember(x => x.Description, m => m.MapFrom(x => x.Route.Description))
            .ForMember(x => x.Navigations, m => m.ResolveUsing((x, dst, arg3, context) => x.Category.GetCategoryNavigations((int)context.Items["WorkingLanguageId"])))
            .ForMember(x => x.ProductDetails, m => m.ResolveUsing((x, dst, arg3, context) => x.ProductDetails.Select(o => new ProductDetailDto()
            {
                Characteristics = CharacteristicsHelper.BuildCharacteristics <ProductDetailCharacteristic, ProductDetailCharacteristicTranslation>(o, o.Characteristics, (int)context.Items["WorkingLanguageId"]),
                Id           = o.Id,
                IsOutOfStock = o.IsOutOfStock,
                Type         = o.ProductDetailType.Code,
                Value        = o.Value
            }).ToList()))
            .ForMember(x => x.Characteristics, m => m.ResolveUsing((x, dst, arg3, context) => CharacteristicsHelper.BuildCharacteristics <ProductCharacteristic, ProductCharacteristicTranslation>(x, x.Characteristics, (int)context.Items["WorkingLanguageId"])))
            .ForMember(x => x.Fieldsets, m => m.ResolveUsing((x, dst, arg3, context) => InputFieldsetsHelper.BuildInputFieldsets(x?.Fieldsets?.Concat(x?.Route?.AngularComponent?.InputFieldsets ?? new List <InputFieldset>())?.ToList(), (int)context.Items["WorkingLanguageId"])))
            .ForMember(x => x.Rating, m => m.MapFrom(x => x.ProductRatings.Sum(o => o.Rate)))
            .ForMember(x => x.SimilarProducts, m => m.Ignore())
            //.ForMember(x => x.SimilarProducts, m => m.MapFrom(x => x.SimilarProducts.ToList()))
            .ForMember(x => x.Title, m => m.MapFrom(x => x.Route.Title))
            .ForMember(x => x.Url, m => m.MapFrom(x => x.Route.Url))
            .ReverseMap()
            .ForMember(x => x.Characteristics, o => o.Ignore())
            .ForMember(x => x.Fieldsets, o => o.Ignore())
            .ForMember(x => x.Category, o => o.Ignore())
            .ForMember(x => x.Images, o => o.Ignore())
            .BeforeMap((x, d) => x.Title = string.IsNullOrEmpty(x.Title) ? x.Characteristics.GetValue(CharacteristicCodes.Name) : x.Title)
            .BeforeMap((x, d) => x.Url   = x.Url == null ? x.Title.ToUrlFriendly() ?? x.Characteristics.GetValue(CharacteristicCodes.Name).ToUrlFriendly() : x.Url);

            CreateMissingTypeMaps = true;
        }
Exemplo n.º 2
0
        protected CategoryItemMapperProfile(string profileName)
            : base(profileName)
        {
            // TODO: fix workingLanguageId
            CreateMap <Category, CategoryItemDto>()
            .ForMember(x => x.Characteristics, m => m.MapFrom(x => CharacteristicsHelper.BuildCharacteristics <CategoryCharacteristic, CategoryCharacteristicTranslation>(x, x.Characteristics, 1)))
            .ForMember(x => x.Url, m => m.MapFrom(x => x.Route.Url));

            CreateMap <Product, CategoryItemDto>()
            .ForMember(x => x.Characteristics, m => m.MapFrom(x => CharacteristicsHelper.BuildCharacteristics <ProductCharacteristic, ProductCharacteristicTranslation>(x, x.Characteristics, 1)))
            .ForMember(x => x.DetailsCount, m => m.MapFrom(x => x.ProductDetails.Count))
            .ForMember(x => x.Url, m => m.MapFrom(x => x.Route.Url));
        }
Exemplo n.º 3
0
        protected ImageMapperProfile(string profileName)
            : base(profileName)
        {
            // TODO: fix working langaugeId
            CreateMap <Image, ImageDto>()
            .ForMember(x => x.Characteristics, m => m.MapFrom(x => CharacteristicsHelper.BuildCharacteristics <ImageCharacteristic, ImageCharacteristicTranslation>(x, x.Characteristics, 1)))
            .ForMember(x => x.ImageSizeType, m => m.MapFrom(x => x.ImageSizeType.Code))
            .ForMember(x => x.ImageSizeTypeId, m => m.MapFrom(x => x.ImageSizeType.Id));

            CreateMap <ImageDto, Image>()
            .ForMember(x => x.Characteristics, o => o.Ignore());

            CreateMissingTypeMaps = true;
        }
Exemplo n.º 4
0
        public static Dictionary <string, InputFieldsetDto> BuildInputFieldsets(List <InputFieldset> inputFieldsets, int workingLanguageId)
        {
            var inputFieldsetsDto = inputFieldsets?.Select(o => new
            {
                Name  = o.Code,
                Value = new InputFieldsetDto()
                {
                    Characteristics = CharacteristicsHelper.BuildCharacteristics <InputFieldsetCharacteristic, InputFieldsetCharacteristicTranslation>(o, o.Characteristics, workingLanguageId),
                    Fields          = o.InputFields.Select(f => new
                    {
                        Name  = f.Code,
                        Value = new InputFieldDto()
                        {
                            Characteristics = CharacteristicsHelper.BuildCharacteristics <InputFieldCharacteristic, InputFieldCharacteristicTranslation>(f, f.Characteristics, workingLanguageId),
                            Value           = f.Value
                        }
                    }).OrderBy(i => i.Value.Characteristics.GetValue(CharacteristicCodes.Order)).ToDictionary(key => key.Name, value => value.Value)
                }
            }).OrderBy(i => i.Value.Characteristics.GetValue(CharacteristicCodes.Order)).ToDictionary(key => key.Name, value => value.Value);

            return(inputFieldsetsDto);
        }
 protected CategoryBreadcrumbMapperProfile(string profileName)
     : base(profileName)
 {
     CreateMap <Category, CategoryNavigationDto>()
     .ForMember(x => x.Characteristics, m => m.ResolveUsing((x, dst, arg3, context) => CharacteristicsHelper.BuildCharacteristics <CategoryCharacteristic, CategoryCharacteristicTranslation>(x, x.Characteristics, (int)context.Items["WorkingLanguageId"])))
     .ForMember(x => x.Parameters, m => m.MapFrom(x => x.Parameter.ToObject <Dictionary <string, object> >()))
     .ForMember(x => x.Type, m => m.MapFrom(x => x.CategoryType.Code))
     .ForMember(x => x.Url, m => m.MapFrom(x => x.Route.Url));
 }
Exemplo n.º 6
0
        protected CategoryMapperProfile(string profileName)
            : base(profileName)
        {
            CreateMap <Category, CategoryDto>()
            .ForMember(x => x.AngularComponentCode, m => m.ResolveUsing(x => x.Route.AngularComponent?.Code))
            .ForMember(x => x.CategoryTypeCode, m => m.ResolveUsing(x => x.CategoryType?.Code))
            .ForMember(x => x.Characteristics, m => m.ResolveUsing((x, dst, arg3, context) => CharacteristicsHelper.BuildCharacteristics <CategoryCharacteristic, CategoryCharacteristicTranslation>(x, x.Characteristics, (int)context.Items["WorkingLanguageId"])))
            .ForMember(x => x.Description, m => m.MapFrom(x => x.Route.Description))
            .ForMember(x => x.Fieldsets, m => m.ResolveUsing((x, dst, arg3, context) => InputFieldsetsHelper.BuildInputFieldsets(x.Fieldsets.Concat(x.Route.AngularComponent.InputFieldsets).ToList(), (int)context.Items["WorkingLanguageId"])))
            .ForMember(x => x.InputFormId, m => m.MapFrom(x => x.Route.InputFormId))
            .ForMember(x => x.Navigations, m => m.ResolveUsing((x, dst, arg3, context) => x.GetCategoryNavigations((int)context.Items["WorkingLanguageId"])))
            .ForMember(x => x.Parameters, m => m.MapFrom(x => x.Parameter.ToObject <Dictionary <string, object> >()))
            .ForMember(x => x.SubCategories, m => m.MapFrom(x => x.Children.ToPagedList()))
            .ForMember(x => x.Title, m => m.MapFrom(x => x.Route.Title))
            .ForMember(x => x.Url, m => m.MapFrom(x => x.Route.Url))
            // The Products is supposed to be set always from the independent service
            .ForMember(x => x.Products, m => m.Ignore())
            .ReverseMap()
            .ForMember(x => x.CategoryType, o => o.Ignore())
            .ForMember(x => x.Characteristics, o => o.Ignore())
            .ForMember(x => x.Fieldsets, o => o.Ignore())
            .ForMember(x => x.Children, o => o.Ignore())
            .ForMember(x => x.Images, o => o.Ignore())
            .ForMember(x => x.Parent, o => o.Ignore())
            .BeforeMap((x, d) => x.Title = string.IsNullOrEmpty(x.Title) ? x.Characteristics.GetValue(CharacteristicCodes.Name) : x.Title)
            .BeforeMap((x, d) => x.Url   = x.Url == null ? x.Title.ToUrlFriendly() ?? x.Characteristics.GetValue(CharacteristicCodes.Name).ToUrlFriendly() : x.Url);

            CreateMissingTypeMaps = true;
        }