コード例 #1
0
        public static Role MapToEntityModel(RoleVm source)
        {
            var config      = new MapperConfiguration(cfg => cfg.CreateMap <RoleVm, Role>());
            var mapper      = config.CreateMapper();
            var destination = mapper.Map <Role>(source);

            return(destination);
        }
コード例 #2
0
ファイル: UserVm.cs プロジェクト: JiriTomasek/EFZ
        public static UserVm MapToViewModel(User source)
        {
            var config = new MapperConfiguration(cfg => cfg.CreateMap <User, UserVm>()
                                                 .ForMember(x => x.Roles, y => y.MapFrom(z => z.UserRoles.Select(item => RoleVm.MapToViewModel(item.Role))))

                                                 .ForMember(x => x.CustomerId, y => y.MapFrom(z => z.CustomerId == null ? 0 : z.CustomerId))
                                                 .ForMember(x => x.Customer, y => y.MapFrom(z => CustomerVm.MapToViewModelNoRelations(z.Customer)))
                                                 .ForMember(x => x.RolesIds, y => y.MapFrom(z => string.Join(",", z.UserRoles.Select(item => item.RoleId.ToString()).ToList())))
                                                 );

            var mapper      = config.CreateMapper();
            var destination = mapper.Map <UserVm>(source);

            return(destination);
        }