public static CompanyVm MapToViewModel(Company source) { var config = new MapperConfiguration(cfg => cfg.CreateMap <Company, CompanyVm>() .ForMember(x => x.Address, y => y.MapFrom(z => AddressVm.MapToViewModel(z.Address))) ); var mapper = config.CreateMapper(); var destination = mapper.Map <CompanyVm>(source); return(destination); }
public static CustomerVm MapToViewModel(Customer source) { var config = new MapperConfiguration(cfg => cfg.CreateMap <Customer, CustomerVm>() .ForMember(x => x.Address, y => y.MapFrom(z => AddressVm.MapToViewModel(z.Address))) .ForMember(x => x.Users, y => y.MapFrom(z => z.Users.Select(UserVm.MapToViewModelNoRelation))) .ForMember(x => x.UserIds, y => y.MapFrom(z => string.Join(",", z.Users.Select(item => item.Id.ToString()).ToList()))) ); var mapper = config.CreateMapper(); var destination = mapper.Map <CustomerVm>(source); return(destination); }