Mapping Files to Litiums Organization Model

What am i doing wrong? I added a Files field for Organization in CustomerArea but my mapping isn’t working. I saw how Litiums demo and it does the same thing for Article Page but the mapping is created from PageModel.

How can i get correct mapping to show my organization files to MyPages view. Thanks in advanced.

   public IList<FileModel> OrganizationFiles { get; set; }

    [UsedImplicitly]
    void IAutoMapperConfiguration.Configure(IMapperConfigurationExpression cfg)
    {
        cfg.CreateMap<PageModel, BusinessCustomerDetailsViewModel>();
        cfg.CreateMap<Person, BusinessCustomerDetailsViewModel>()
            .ForMember(x => x.CustomerNumber, m => m.MapFrom(person => person.Id))
            .ReverseMap();
        cfg.CreateMap<Organization, BusinessCustomerDetailsViewModel>()
            .ForMember(x => x.OrganizationNumber, m => m.MapFrom(organization => organization.Id))
            .ForMember(x => x.OrganizationName, m => m.MapFrom(organization => organization.Name))
            .ForMember(x => x.OrganizationFiles, m => m.MapFrom(files => files.Fields.GetValue<IList<Guid>>(GcCustomerNameConstants.OrganizationFiles)
                    .Select(x => x.MapTo<FileModel>())));
    }

Unable to cast object of type ‘System.Collections.ObjectModel.ReadOnlyCollection1[Litium.FieldFramework.FieldTypes.PointerItem]' to type 'System.Collections.Generic.IList1[System.Guid]’.

Litium version: 7.2

I see now that Organization uses GetValue from FieldContainer and PageModel uses GetValue from FieldFrameworkModel. Is there a way to do a correct cast or use GetValue from FieldFrameworkModel?

Try retrieving it as PointerItem and use the SystemId from that to do the mapping.

	cfg.CreateMap<Organization, BusinessCustomerDetailsViewModel>()
	   .ForMember(x => x.OrganizationNumber, m => m.MapFrom(organization => organization.Id))
	   .ForMember(x => x.OrganizationName, m => m.MapFrom(organization => organization.Name))
	   .ForMember(x => x.OrganizationFiles, m => m.MapFrom(files => files.Fields.GetValue<IList<PointerItem>>(GcCustomerNameConstants.OrganizationFiles)
		.Select(x => x.EntitySystemId.MapTo<FileModel>())));

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.