Пример #1
0
        public UserProfile()
        {
            CreateMap <User, SelectListItem>().ConvertUsing(
                (src, target) =>
            {
                var languageId = HttpContext.Current.Request.RequestContext.CurrectLanguageId();
                return(new SelectListItem
                {
                    Text = src.GetLocalized(x => x.UserName, languageId),
                    Value = src.Id.ToString()
                });
            });

            CreateMap <User, UserViewModel>()
            .ForMember(vm => vm.Biography, opt => opt.ResolveUsing(x =>
            {
                var languageId = HttpContext.Current.Request.RequestContext.CurrectLanguageId();
                return(x.GetLocalized(item => item.Biography, languageId));
            }))
            .ForMember(vm => vm.Title, opt => opt.ResolveUsing(x =>
            {
                var languageId = HttpContext.Current.Request.RequestContext.CurrectLanguageId();
                return(x.GetLocalized(item => item.Title, languageId));
            }))
            .ForMember(vm => vm.UserName, opt => opt.ResolveUsing(x =>
            {
                var languageId = HttpContext.Current.Request.RequestContext.CurrectLanguageId();
                return(x.GetLocalized(item => item.UserName, languageId));
            }))
            .ForMember(vm => vm.ImageId, opt => opt.MapFrom(user => user.ImageId))
            .ForMember(vm => vm.TechnologiesIds, opt => opt.MapFrom(item => item.Technologies.Select(t => t.ID).ToArray()));


            CreateMap <UserViewModel, User>()
            .AfterMap((vm, entity) =>
            {
                if (vm.File != null)
                {
                    entity.Image = (File)MapperImageConverter.ImageConverter(vm);
                }
            });

            CreateMap <RegisterViewModel, User>()
            .AfterMap((vm, entity) =>
            {
                if (vm.File != null)
                {
                    entity.Image = (File)MapperImageConverter.ImageConverter(vm);
                }
            });
        }
        public ClientProfile()
        {
            CreateMap <Client, SelectListItem>().ConvertUsing(
                (src, target) =>
            {
                var languageId = HttpContext.Current.Request.RequestContext.CurrectLanguageId();

                return(new SelectListItem
                {
                    Text = string.Format("{0} {1} ({2})",
                                         src.GetLocalized(x => x.FirstName, languageId),
                                         src.GetLocalized(x => x.LastName, languageId),
                                         src.GetLocalized(x => x.Company, languageId)),
                    Value = src.ID.ToString()
                });
            });

            CreateMap <Client, ClientViewModel>()
            .ForMember(vm => vm.Title, opt => opt.ResolveUsing(x =>
            {
                var languageId = HttpContext.Current.Request.RequestContext.CurrectLanguageId();
                return(x.GetLocalized(item => item.Title, languageId));
            }))
            .ForMember(vm => vm.Company, opt => opt.ResolveUsing(x =>
            {
                var languageId = HttpContext.Current.Request.RequestContext.CurrectLanguageId();
                return(x.GetLocalized(item => item.Company, languageId));
            }))
            .ForMember(vm => vm.FirstName, opt => opt.ResolveUsing(x =>
            {
                var languageId = HttpContext.Current.Request.RequestContext.CurrectLanguageId();
                return(x.GetLocalized(item => item.FirstName, languageId));
            }))
            .ForMember(vm => vm.LastName, opt => opt.ResolveUsing(x =>
            {
                var languageId = HttpContext.Current.Request.RequestContext.CurrectLanguageId();
                return(x.GetLocalized(item => item.LastName, languageId));
            }))
            .ForMember(viewModel => viewModel.ImageId, opt => opt.MapFrom(client => client.ImageId));

            CreateMap <ClientViewModel, Client>().AfterMap((vm, entity) =>
            {
                if (vm.File != null)
                {
                    entity.Image = (File)MapperImageConverter.ImageConverter(vm);
                }
            });
        }
        public ServiceProfile()
        {
            CreateMap <Service, SelectListItem>().ConvertUsing(
                (src, target) =>
            {
                var languageId = HttpContext.Current.Request.RequestContext.CurrectLanguageId();

                return(new SelectListItem
                {
                    Text = src.GetLocalized(x => x.Title, languageId),
                    Value = src.ID.ToString()
                });
            });

            CreateMap <Service, ServiceViewModel>()
            .ForMember(vm => vm.Title, opt => opt.ResolveUsing(x =>
            {
                var languageId = HttpContext.Current.Request.RequestContext.CurrectLanguageId();
                return(x.GetLocalized(item => item.Title, languageId));
            }))
            .ForMember(vm => vm.SubTitle, opt => opt.ResolveUsing(x =>
            {
                var languageId = HttpContext.Current.Request.RequestContext.CurrectLanguageId();
                return(x.GetLocalized(item => item.SubTitle, languageId));
            }))
            .ForMember(vm => vm.Description, opt => opt.ResolveUsing(x =>
            {
                var languageId = HttpContext.Current.Request.RequestContext.CurrectLanguageId();
                return(x.GetLocalized(item => item.Description, languageId));
            }))
            .ForMember(vm => vm.Content, opt => opt.ResolveUsing(x =>
            {
                var languageId = HttpContext.Current.Request.RequestContext.CurrectLanguageId();
                return(x.GetLocalized(item => item.Content, languageId));
            }));

            CreateMap <ServiceViewModel, Service>()
            .AfterMap((vm, entity) =>
            {
                if (vm.File != null)
                {
                    entity.Image = (File)MapperImageConverter.ImageConverter(vm);
                }
            });
        }
        public ServiceCategoryProfile()
        {
            CreateMap <ServiceCategory, SelectListItem>().ConvertUsing(
                (src, target) =>
            {
                var languageId = HttpContext.Current.Request.RequestContext.CurrectLanguageId();

                return(new SelectListItem
                {
                    Text = src.GetLocalized(x => x.Name, languageId),
                    Value = src.ID.ToString()
                });
            });

            CreateMap <ServiceCategory, ServiceCategoryViewModel>()
            .ForMember(vm => vm.ServiceSubcategories, opt => opt.MapFrom(entity => entity.ServiceSubcategories))
            .ForMember(vm => vm.Name, opt => opt.ResolveUsing(x =>
            {
                var languageId = HttpContext.Current.Request.RequestContext.CurrectLanguageId();
                return(x.GetLocalized(item => item.Name, languageId));
            }))
            .ForMember(vm => vm.Content, opt => opt.ResolveUsing(x =>
            {
                var languageId = HttpContext.Current.Request.RequestContext.CurrectLanguageId();
                return(x.GetLocalized(item => item.Content, languageId));
            }));


            CreateMap <ServiceCategoryViewModel, ServiceCategory>()
            .AfterMap((vm, entity) =>
            {
                if (vm.File != null)
                {
                    entity.Image = (File)MapperImageConverter.ImageConverter(vm);
                }
            });
        }
        public SliderProfile()
        {
            CreateMap <Slider, SliderViewModel>()
            .ForMember(vm => vm.Title, opt => opt.ResolveUsing(x =>
            {
                var languageId = HttpContext.Current.Request.RequestContext.CurrectLanguageId();
                return(x.GetLocalized(item => item.Title, languageId));
            }))
            .ForMember(vm => vm.Description, opt => opt.ResolveUsing(x =>
            {
                var languageId = HttpContext.Current.Request.RequestContext.CurrectLanguageId();
                return(x.GetLocalized(item => item.Description, languageId));
            }))
            .ForMember(viewModel => viewModel.ImageId, opt => opt.MapFrom(client => client.ImageId));

            CreateMap <SliderViewModel, Slider>()
            .AfterMap((vm, entity) =>
            {
                if (vm.File != null)
                {
                    entity.Image = (File)MapperImageConverter.ImageConverter(vm);
                }
            });
        }
Пример #6
0
        public ProjectProfile()
        {
            CreateMap <Project, SelectListItem>().ConvertUsing(
                (src, target) =>
            {
                var languageId = HttpContext.Current.Request.RequestContext.CurrectLanguageId();

                return(new SelectListItem
                {
                    Text = src.GetLocalized(x => x.Title, languageId),
                    Value = src.ID.ToString()
                });
            });

            CreateMap <Project, ProjectViewModel>()
            .ForMember(vm => vm.Client, opt => opt.ResolveUsing(e =>
            {
                return(Mapper.Map <ClientViewModel>(e.Client));
            }))
            .ForMember(vm => vm.TechnologiesIds, opt => opt.MapFrom(item => item.Technologies.Select(t => t.ID).ToArray()))
            .ForMember(vm => vm.ServicesIds, opt => opt.MapFrom(item => item.Services.Select(s => s.ID).ToArray()))
            .ForMember(vm => vm.ContributorsIds, opt => opt.MapFrom(item => item.Contributors.Select(s => s.Id).ToArray()))
            .ForMember(vm => vm.Logo, opt => opt.Ignore())
            .ForMember(vm => vm.LogoId, opt => opt.MapFrom(project => project.LogoId))
            .ForMember(vm => vm.ImageId, opt => opt.MapFrom(project => project.ImageId))
            .ForMember(vm => vm.Title, opt => opt.ResolveUsing(x =>
            {
                var languageId = HttpContext.Current.Request.RequestContext.CurrectLanguageId();
                return(x.GetLocalized(item => item.Title, languageId));
            }))
            .ForMember(vm => vm.Kewywords, opt => opt.ResolveUsing(x =>
            {
                var languageId = HttpContext.Current.Request.RequestContext.CurrectLanguageId();
                return(x.GetLocalized(item => item.Kewywords, languageId));
            }))
            .ForMember(vm => vm.Overview, opt => opt.ResolveUsing(x =>
            {
                var languageId = HttpContext.Current.Request.RequestContext.CurrectLanguageId();
                return(x.GetLocalized(item => item.Overview, languageId));
            }))
            .ForMember(vm => vm.Objective, opt => opt.ResolveUsing(x =>
            {
                var languageId = HttpContext.Current.Request.RequestContext.CurrectLanguageId();
                return(x.GetLocalized(item => item.Objective, languageId));
            }))
            .ForMember(vm => vm.WorkOverview, opt => opt.ResolveUsing(x =>
            {
                var languageId = HttpContext.Current.Request.RequestContext.CurrectLanguageId();
                return(x.GetLocalized(item => item.WorkOverview, languageId));
            }))
            .ForMember(vm => vm.ResultOverview, opt => opt.ResolveUsing(x =>
            {
                var languageId = HttpContext.Current.Request.RequestContext.CurrectLanguageId();
                return(x.GetLocalized(item => item.ResultOverview, languageId));
            }));


            CreateMap <ProjectViewModel, Project>()
            .ForMember(entity => entity.Client, opt => opt.Ignore())
            .ForMember(entity => entity.Technologies, opt => opt.Ignore())
            .ForMember(entity => entity.Services, opt => opt.Ignore())
            .ForMember(entity => entity.Contributors, opt => opt.Ignore())
            .ForMember(entity => entity.Logo, opt => opt.Ignore())
            .AfterMap((vm, entity) =>
            {
                if (vm.Logo != null)
                {
                    entity.Logo = (File)MapperImageConverter.ImageConverter(vm.Logo);
                }
                if (vm.File != null)
                {
                    entity.Image = (File)MapperImageConverter.ImageConverter(vm);
                }
            });
        }