public static void Initialize(IMapperConfiguration mapperConfig)
 {
     mapperConfig
         .CreateMap<GuessThePicture.DataAccessContracts.Dto.PictureDto, GuessThePicture.Domain.Entities.Picture>()
         .ForMember(i => i.Style, x => x.ResolveUsing(t => t.Style.Name))
         .ForMember(i => i.Campaigns, x => x.Ignore());
 }
        private static void TeamMapping(IMapperConfiguration cfg)
        {
            cfg.CreateMap<TeamPlayerEntity, TeamPlayer>()
                .ForMember(
                    dest => dest.Type,
                    opts => opts.MapFrom(src => src.PlayerType));

            cfg.CreateMap<TeamEntity, Team>()
            .ForMember(
                dest => dest.ClubId,
                opts => opts.MapFrom(src => Constants.OwnClubId))
            .ForMember(
                dest => dest.Competition,
                opts => opts.MapFrom(src => Constants.NormalizeCompetition(src.Competition)))
            .ForMember(
                dest => dest.DivisionName,
                opts => opts.MapFrom(src => src.ReeksNummer + src.ReeksCode))
            .ForMember(
                dest => dest.Frenoy,
                opts => opts.MapFrom(src => new FrenoyTeamLinks
                {
                    DivisionId = src.FrenoyDivisionId,
                    LinkId = src.LinkId,
                    TeamId = src.FrenoyTeamId
                }))
            .ForMember(
                dest => dest.Players,
                opts => opts.MapFrom(src => src.Players))
            .ForMember(
                dest => dest.Opponents,
                opts => opts.MapFrom(src => MapAllTeams(src)))
            ;
        }
 public RenderDataObjectsAutoMapper(RequestContext context, IMapperConfiguration mapperConfiguration,
     IMapperExtensions mapperExtensions)
     : base(context.Zeus.Output)
 {
     this._mapperExtensions = mapperExtensions;
     this._mapperConfiguration = mapperConfiguration;
     this._context = context;
 }
 public override void CreateMappings(IMapperConfiguration configuration)
 {
     configuration.CreateMap<Organisation, OrganisationDetailsModel>()
         .ForMember(x => x.Owner, opt => opt.MapFrom(x => x.Owner.Email))
         .ForMember(
             x => x.Tests,
             opt => opt.MapFrom(x => x.Tests))
         .ForMember(x => x.Users, opt => opt.MapFrom(x => x.Users));
 }
        public static void Initialize(IMapperConfiguration mapperConfig)
        {
            mapperConfig.CreateMap<Campaign, CampaignDto>();
            mapperConfig.CreateMap<Picture, PictureDto>();
            mapperConfig.CreateMap<Style, StyleDto>();
            mapperConfig.CreateMap<Painter, PainterDto>();

            mapperConfig.CreateMap<DataAccess.CampaignDto, Domain.Campaign>();
        }
Пример #6
0
 //методы
 public static void Configure(IMapperConfiguration configuration)
 {
     configuration.CreateMap<SignalBounce<Guid>, SignalBounceGuid>();
     configuration.CreateMap<SignalDispatchBase<Guid>, SignalDispatchBaseGuid>();
     configuration.CreateMap<SubjectDispatch<Guid>, SubjectDispatchGuid>();
     configuration.CreateMap<UserCategorySettings<Guid>, UserCategorySettingsGuid>();
     configuration.CreateMap<UserDeliveryTypeSettings<Guid>, UserDeliveryTypeSettingsGuid>();
     configuration.CreateMap<UserReceivePeriod<Guid>, UserReceivePeriodGuid>();
     configuration.CreateMap<UserTopicSettings<Guid>, UserTopicSettingsGuid>();
 }
Пример #7
0
        private static void LoadCustomMappings(IEnumerable<Type> types, IMapperConfiguration mapperConfiguration)
        {
            var maps = types
                .Where(t => !t.IsInterface && !t.IsAbstract && t.GetInterfaces()
                    .Any(i => typeof(IHaveCustomMappings).IsAssignableFrom(i)))
                .Select(t => (IHaveCustomMappings)Activator.CreateInstance(t))
                .ToList();

            maps.ForEach(m => m.CreateMappings(mapperConfiguration));
        }
Пример #8
0
 public void CreateMappings(IMapperConfiguration configuration)
 {
     configuration.CreateMap<User, UserInfoViewModel>()
         .ForMember(
             self => self.QuizzesCreated,
             opt => opt.MapFrom(model => model.QuizzesCreated.Count))
         .ForMember(
             self => self.QuizzesTaken,
             opt => opt.MapFrom(model => model.SolutionsSubmited.Count));
 }
Пример #9
0
 private static void ConfigureUserMapping(IMapperConfiguration cfg)
 {
     cfg.CreateMap<UserToRegisterViewModel, User>();
     cfg.CreateMap<UserToLoginViewModel, User>();
     cfg.CreateMap<UserToActivateViewModel, User>();
     cfg.CreateMap<UserToRemindPasswordViewModel, User>();
     cfg.CreateMap<UserToSendActivationCodeViewModel, User>();
     cfg.CreateMap<UserToSendRemindPasswordRequestViewModel, User>();
     cfg.CreateMap<User, User>().ForAllMembers(opt => opt.Condition(c => !c.IsSourceValueNull));
 }
 public void Configure(IMapperConfiguration mapperConfiguration)
 {
     mapperConfiguration.CreateMap<NewTask, Data.Entities.Task>()
         .ForMember(opt => opt.Version, x => x.Ignore())
         .ForMember(opt => opt.CreatedBy, x => x.Ignore())
         .ForMember(opt => opt.TaskId, x => x.Ignore())
         .ForMember(opt => opt.CreatedDate, x => x.Ignore())
         .ForMember(opt => opt.CompletedDate, x => x.Ignore())
         .ForMember(opt => opt.Status, x => x.Ignore())
         .ForMember(opt => opt.Users, x => x.Ignore());
 }
Пример #11
0
        private static void LoadAllMappings(IMapperConfiguration config, params string[] assemblies)
        {
            var types = new List<Type>();
            foreach (var assembly in assemblies.Select(a => Assembly.Load(a)))
            {
                types.AddRange(assembly.GetExportedTypes());
            }

            LoadStandardMappings(config, types);
            LoadCustomMappings(config, types);
        }
        private static void LoadCustomMappings(IEnumerable<Type> types, IMapperConfiguration mapperConfiguration)
        {
            var maps = (from t in types
                        from i in t.GetInterfaces()
                        where typeof(IHaveCustomMappings).IsAssignableFrom(t) && !t.IsAbstract && !t.IsInterface
                        select (IHaveCustomMappings)Activator.CreateInstance(t)).ToArray();

            foreach (var map in maps)
            {
                map.CreateMappings(mapperConfiguration);
            }
        }
Пример #13
0
        public static void ConfigureMaps(IMapperConfiguration cfg)
        {
            cfg.CreateMap< AuthLoginInfo, AuthLoginInfoPoco>()
            .ForMember(s => s.UserName, m => m.MapFrom(s => s.UserName))
            .ForMember(s => s.PasswordSalt, m => m.MapFrom(s => s.PasswordSalt))
            .ForMember(s => s.HashedPassword, m => m.MapFrom(s => s.HashedPassword));

              cfg.CreateMap<AuthLoginInfoPoco, AuthLoginInfo>()
            .ForMember(s => s.UserName, m => m.MapFrom(s => s.UserName))
            .ForMember(s => s.PasswordSalt, m => m.MapFrom(s => s.PasswordSalt))
            .ForMember(s => s.HashedPassword, m => m.MapFrom(s => s.HashedPassword));
        }
        private static void LoadStandardMappings(IEnumerable <Type> types, IMapperConfiguration mapperConfiguration)
        {
            var maps = (from t in types
                        from i in t.GetInterfaces()
                        where
                        i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IMapFrom <>) && !t.IsAbstract &&
                        !t.IsInterface
                        select new { Source = i.GetGenericArguments()[0], Destination = t }).ToArray();

            foreach (var map in maps)
            {
                mapperConfiguration.CreateMap(map.Source, map.Destination);
            }
        }
Пример #15
0
 public void CreateMappings(IMapperConfiguration configuration)
 {
     configuration.CreateMap<TvShow, AllTvShowsTvShowViewModel>()
         .ForMember(x => x.RatingsCount, opt => opt.MapFrom(x => x.Ratings.Sum(v => v.Value) / x.Ratings.Count()))
         .ForMember(x => x.CommentsCount, opt => opt.MapFrom(x => x.Comments.Count))
         .ForMember(x => x.LeadActor, opt => opt.MapFrom(x => x.Actors.OrderByDescending(a => a.CreatedOn)
         .Select(n => new { FullName = n.FirstName + " " + n.LastName })
         .Select(n => n.FullName).FirstOrDefault()))
         .ForMember(x => x.SupportActor, opt => opt.MapFrom(x => x.Actors.OrderByDescending(a => a.CreatedOn)
         .Skip(1)
         .Select(n => new { FullName = n.FirstName + " " + n.LastName })
         .Select(n => n.FullName).FirstOrDefault()))
         .ForMember(x => x.Channel, opt => opt.MapFrom(x => x.Channel.Name));
 }
Пример #16
0
        private static void LoadCustomMappings(IMapperConfiguration mapperConfiguration, IEnumerable<Type> types)
        {
            IEnumerable<IHaveCustomMappings> maps = types
                .SelectMany(t => t.GetInterfaces(), (t, i) => new { t, i })
                .Where(type => typeof(IHaveCustomMappings).IsAssignableFrom(type.t) &&
                               !type.t.IsAbstract &&
                               !type.t.IsInterface)
                .Select(type => (IHaveCustomMappings)Activator.CreateInstance(type.t));

            foreach (var map in maps)
            {
                map.CreateMappings(mapperConfiguration);
            }
        }
Пример #17
0
        private static void LoadCustomMappings(IEnumerable <Type> types, IMapperConfiguration mapperConfiguration)
        {
            var maps = (from t in types
                        from i in t.GetInterfaces()
                        where typeof(IHaveCustomMappings).IsAssignableFrom(t) &&
                        !t.IsAbstract &&
                        !t.IsInterface
                        select(IHaveCustomMappings) Activator.CreateInstance(t)).ToArray();

            foreach (var map in maps)
            {
                map.CreateMappings(mapperConfiguration);
            }
        }
        public void CreateMappings(IMapperConfiguration configuration)
        {
            var context             = new ApplicationDbContext();
            var rolerManager        = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(context));
            var administratorRoleId =
                rolerManager.Roles.Where(r => r.Name == GlobalConstants.AdminRoleName)
                .Select(r => r.Id)
                .FirstOrDefault();

            configuration.CreateMap <ApplicationUser, ApplicationUserViewModel>()
            .ForMember(
                model => model.IsAdmin,
                config => config.MapFrom(e => e.Roles.Any(r => r.RoleId == administratorRoleId)));
        }
        private static void LoadStandardMappings(IEnumerable<Type> types, IMapperConfiguration mapperConfiguration)
        {
            var maps = (from t in types
                        from i in t.GetInterfaces()
                        where
                            i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IMapFrom<>) && !t.IsAbstract
                            && !t.IsInterface
                        select new { Source = i.GetGenericArguments()[0], Destination = t }).ToArray();

            foreach (var map in maps)
            {
                mapperConfiguration.CreateMap(map.Source, map.Destination);
            }
        }
Пример #20
0
        private static void LoadCustomMappings(IMapperConfiguration mapperConfiguration, IList<Type> types)
        {
            var maps = (from t in types
                        from i in t.GetInterfaces()
                        where typeof(IHaveCustomMappings).IsAssignableFrom(t) &&
                              !t.IsAbstract &&
                              !t.IsInterface
                        select InitializeCustomMappingObject(t)).ToArray();

            foreach (var map in maps)
            {
                map.CreateMappings(mapperConfiguration);
            }
        }
Пример #21
0
 public void CreateMappings(IMapperConfiguration configuration)
 {
     configuration.CreateMap <ApplicationUser, UserViewModel>()
     .ForMember(x => x.City, opt => opt.MapFrom(x => x.City.Name))
     .ForMember(x => x.FPSTutorialsAdded, opt => opt.MapFrom(x => x.Articles.Any() ? x.Articles.Count(y => y.Type == TutorialType.FPS && !y.IsDeleted) : 0))
     .ForMember(x => x.StrategyTutrialAdded, opt => opt.MapFrom(x => x.Articles.Any() ? x.Articles.Count(y => y.Type == TutorialType.Strategy && !y.IsDeleted) : 0))
     .ForMember(x => x.SellingItemsAdded, opt => opt.MapFrom(x => x.SellingItems.Any() ? x.SellingItems.Count(y => !y.IsDeleted) : 0))
     .ForMember(x => x.CoursesAsTrainer, opt => opt.MapFrom(x => x.CoursesTraining.Any() ? x.CoursesTraining.Count(y => !y.IsDeleted) : 0))
     .ForMember(x => x.CoursesAsStudent, opt => opt.MapFrom(x => x.CoursesStuding.Any() ? x.CoursesStuding.Count(y => !y.IsDeleted) : 0))
     .ForMember(x => x.PurchasesMade, opt => opt.MapFrom(x => x.Purchases.Any() ? x.Purchases.Count(y => !y.IsDeleted) : 0))
     .ForMember(x => x.CommentsMade, opt => opt.MapFrom(x => x.Comments.Any() ? x.Comments.Count(y => !y.IsDeleted) : 0))
     .ForMember(x => x.LikesGiven, opt => opt.MapFrom(x => x.Likes.Any() ? x.Likes.Count(y => !y.IsDeleted) : 0))
     ;
 }
Пример #22
0
        private static void CreateApprenticeshipDetailsMappings(IMapperConfiguration cfg)
        {
            // Standard detail page
            cfg.CreateMap <GetStandardResponse, StandardViewModel>()
            .ForMember(x => x.StandardId, y => y.MapFrom(z => z.Standard.StandardId))
            .ForMember(x => x.EntryRequirements, y => y.MapFrom(z => z.Standard.EntryRequirements))
            .ForMember(x => x.Level, y => y.MapFrom(z => z.Standard.Level))
            .ForMember(x => x.MaxFunding, y => y.MapFrom(z => z.Standard.MaxFunding))
            .ForMember(x => x.OverviewOfRole, y => y.MapFrom(z => z.Standard.OverviewOfRole))
            .ForMember(x => x.ProfessionalRegistration, y => y.MapFrom(z => z.Standard.ProfessionalRegistration))
            .ForMember(x => x.Qualifications, y => y.MapFrom(z => z.Standard.Qualifications))
            .ForMember(x => x.SearchTerm, y => y.MapFrom(z => z.SearchTerms))
            .ForMember(x => x.Title, y => y.MapFrom(z => z.Standard.Title))
            .ForMember(x => x.RegulatedStandard, y => y.MapFrom(z => z.Standard.RegulatedStandard))
            .ForMember(x => x.Duration, y => y.MapFrom(z => z.Standard.Duration))
            .ForMember(x => x.WhatApprenticesWillLearn, y => y.MapFrom(z => z.Standard.WhatApprenticesWillLearn))
            .ForMember(x => x.AssessmentOrganisations, y => y.MapFrom(z => z.AssessmentOrganisations))
            .ForMember(x => x.StandardPageUri, y => y.MapFrom(z => z.Standard.StandardPageUri))
            .ForMember(x => x.LastDateForNewStarts, y => y.MapFrom(z => z.Standard.LastDateForNewStarts))
            .ForMember(x => x.NextEffectiveFrom, y => y.Ignore())
            .ForMember(x => x.NextFundingCap, y => y.Ignore())
            .ForMember(x => x.FindApprenticeshipTrainingText, y => y.Ignore())
            .ForMember(x => x.ReturnToApprenticeshipSearch, y => y.Ignore())
            .ForMember(x => x.Ukprn, y => y.Ignore());

            // Framework detail page
            cfg.CreateMap <GetFrameworkResponse, FrameworkViewModel>()
            .ForMember(x => x.CombinedQualificiation, y => y.MapFrom(z => z.Framework.CombinedQualification))
            .ForMember(x => x.CompetencyQualification, y => y.MapFrom(z => z.Framework.CompetencyQualification))
            .ForMember(x => x.CompletionQualifications, y => y.MapFrom(z => z.Framework.CompletionQualifications))
            .ForMember(x => x.EntryRequirements, y => y.MapFrom(z => z.Framework.EntryRequirements))
            .ForMember(x => x.ExpiryDateString, y => y.MapFrom(z => ApprenticeshipMappingHelper.GetExpirydateAsString(z.Framework.ExpiryDate)))
            .ForMember(x => x.FrameworkId, y => y.MapFrom(z => z.Framework.FrameworkId))
            .ForMember(x => x.FrameworkOverview, y => y.MapFrom(z => z.Framework.FrameworkOverview))
            .ForMember(x => x.JobRoles, y => y.MapFrom(z => ApprenticeshipMappingHelper.GetTitlesFromJobRoles(z.Framework.JobRoleItems)))
            .ForMember(x => x.KnowledgeQualification, y => y.MapFrom(z => z.Framework.KnowledgeQualification))
            .ForMember(x => x.Level, y => y.MapFrom(z => z.Framework.Level))
            .ForMember(x => x.MaxFunding, y => y.MapFrom(z => z.Framework.MaxFunding))
            .ForMember(x => x.ProfessionalRegistration, y => y.ResolveUsing <FrameworkInformationResolver>().FromMember(z => z.Framework.ProfessionalRegistration))
            .ForMember(x => x.SearchTerm, y => y.MapFrom(z => z.SearchTerms))
            .ForMember(x => x.Duration, y => y.MapFrom(z => z.Framework.Duration))
            .ForMember(x => x.Title, y => y.MapFrom(z => ApprenticeshipMappingHelper.FrameworkTitle(z.Framework.Title)))
            .ForMember(x => x.NextEffectiveFrom, y => y.Ignore())
            .ForMember(x => x.NextFundingCap, y => y.Ignore())
            .ForMember(x => x.FindApprenticeshipTrainingText, y => y.Ignore())
            .ForMember(x => x.ReturnToApprenticeshipSearch, y => y.Ignore())
            .ForMember(x => x.Ukprn, y => y.Ignore())
            ;
        }
Пример #23
0
 public void CreateMappings(IMapperConfiguration configuration)
 {
     configuration.CreateMap <Post, AddPostViewModel>()
     .ForMember(x => x.PostType, opt => opt.MapFrom(x => x.PostType))
     .ForMember(x => x.AnimalType, opt => opt.MapFrom(x => x.Pet.PetType.ToString()))
     .ForMember(x => x.Author, opt => opt.MapFrom(x => x.Author.UserName))
     .ForMember(x => x.PetName, opt => opt.MapFrom(x => x.Pet.Name))
     .ForMember(x => x.PetAge, opt => opt.MapFrom(x => x.Pet.Age))
     .ForMember(x => x.PetDescription, opt => opt.MapFrom(x => x.Pet.Description))
     .ForMember(x => x.PetColor, opt => opt.MapFrom(x => x.Pet.Color))
     .ForMember(x => x.LocationCity, opt => opt.MapFrom(x => x.Location.City.ToString()))
     .ForMember(x => x.LocationStreet, opt => opt.MapFrom(x => x.Location.Street))
     .ForMember(x => x.LocationAdditionalInfo, opt => opt.MapFrom(x => x.Location.AdditionalInfo))
     .ReverseMap();
 }
Пример #24
0
        private void FindAndAutoMapTypes(IMapperConfiguration cfg)
        {
            var types = _typeFinder.Find(type =>
                                         type.IsDefined(typeof(AutoMapAttribute)) ||
                                         type.IsDefined(typeof(AutoMapFromAttribute)) ||
                                         type.IsDefined(typeof(AutoMapToAttribute))
                                         );

            Logger.DebugFormat("Found {0} classes defines auto mapping attributes", types.Length);
            foreach (var type in types)
            {
                Logger.Debug(type.FullName);
                AutoMapperHelper.CreateMap(type, cfg);
            }
        }
Пример #25
0
 public void CreateMappings(IMapperConfiguration configuration)
 {
     configuration.CreateMap <Post, PostConciseViewModel>()
     .ForMember(p => p.Author, config => config.MapFrom(p => p.Author.UserName));
     configuration.CreateMap <Post, PostConciseViewModel>()
     .ForMember(p => p.Category, config => config.MapFrom(p => p.Category.Title));
     configuration.CreateMap <Post, PostConciseViewModel>()
     .ForMember(p => p.AnswersCount, config => config.MapFrom(p => p.Answers.Count(a => !a.IsDeleted)));
     configuration.CreateMap <Post, PostConciseViewModel>()
     .ForMember(p => p.AuthorPictureUrl, config => config.MapFrom(p => p.Author.PictureUrl));
     configuration.CreateMap <Post, PostConciseViewModel>()
     .ForMember(p => p.ReportsCount, config => config.MapFrom(p => p.Reports.Count(r => !r.IsDeleted)));
     configuration.CreateMap <Post, PostConciseViewModel>()
     .ForMember(p => p.LikesCount, config => config.MapFrom(p => p.Likes.Count(l => !l.IsDeleted)));
 }
Пример #26
0
 public void CreateMappings(IMapperConfiguration configuration)
 {
     configuration.CreateMap <Quiz, QuizBasicViewModel>()
     .ForMember(
         self => self.QuestionsCount,
         opt => opt.MapFrom(
             dest => dest.NumberOfQuestions > 0 ? dest.NumberOfQuestions : dest.Questions.Count))
     .ForMember(
         self => self.HasMultipleSolutions,
         opt => opt.MapFrom(
             dest => dest.NumberOfQuestions > 0 && dest.NumberOfQuestions + 10 < dest.Questions.Count))
     .ForMember(
         self => self.TotalTimesCompleted,
         opt => opt.MapFrom(model => model.Solutions.Count));
 }
Пример #27
0
        private void CreateMappings(IMapperConfiguration cfg)
        {
            lock (_syncObj)
            {
                //We should prevent duplicate mapping in an application, since AutoMapper is static.
                if (_createdMappingsBefore)
                {
                    return;
                }

                FindAndAutoMapTypes(cfg);
                CreateOtherMappings(cfg);

                _createdMappingsBefore = true;
            }
        }
Пример #28
0
        public static void ConfigureClients(IMapperConfiguration config)
        {
            config.CreateMap <DataLayer.Client, Models.Client>().BeforeMap((source, destination) =>
            {
                source.Currency.Configure(currency => currency.Clients.Clear());
                source.Orders.Configure(order => order.Client       = null);
                source.Payrolls.Configure(payroll => payroll.Client = null);
            });

            config.CreateMap <Models.Client, DataLayer.Client>().BeforeMap((source, destination) =>
            {
                source.Currency.Configure(currency => currency.Clients.Clear());
                source.Orders.Configure(order => order.Client       = null);
                source.Payrolls.Configure(payroll => payroll.Client = null);
            });
        }
        private static void ReportMapping(IMapperConfiguration cfg)
        {
            cfg.CreateMap <MatchCommentEntity, MatchComment>().ReverseMap();
            cfg.CreateMap <MatchPlayerEntity, MatchPlayer>().ReverseMap();

            cfg.CreateMap <MatchGameEntity, MatchGame>()
            .ForMember(d => d.Outcome, o => o.MapFrom(src => src.WalkOver == WalkOver.None ? MatchOutcome.NotYetPlayed : MatchOutcome.WalkOver))
            .ForMember(
                dest => dest.OutPlayerSets,
                opts => opts.MapFrom(src => src.AwayPlayerSets))
            .ForMember(
                dest => dest.OutPlayerUniqueIndex,
                opts => opts.MapFrom(src => src.AwayPlayerUniqueIndex))
            .ReverseMap()
            ;
        }
        private static void ReportMapping(IMapperConfiguration cfg)
        {
            cfg.CreateMap<MatchCommentEntity, MatchComment>().ReverseMap();
            cfg.CreateMap<MatchPlayerEntity, MatchPlayer>().ReverseMap();

            cfg.CreateMap<MatchGameEntity, MatchGame>()
                .ForMember(d => d.Outcome, o => o.MapFrom(src => src.WalkOver == WalkOver.None ? MatchOutcome.NotYetPlayed : MatchOutcome.WalkOver))
                .ForMember(
                    dest => dest.OutPlayerSets,
                    opts => opts.MapFrom(src => src.AwayPlayerSets))
                .ForMember(
                    dest => dest.OutPlayerUniqueIndex,
                    opts => opts.MapFrom(src => src.AwayPlayerUniqueIndex))
                .ReverseMap()
                ;
        }
Пример #31
0
        internal static void ConfigureCommit(IMapperConfiguration config)
        {
            config.CreateMap <DataLayer.Commit, Commit>();

            config.CreateMap <Commit, DataLayer.Commit>()
            .ForMember(m => m.Project, o => o.Ignore());

            config.CreateMap <GitCommitWrapper, Commit>()
            .ForMember(m => m.Id, o => o.MapFrom(s => Guid.NewGuid()))
            .ForMember(m => m.Project, o => o.Ignore())
            .ForMember(m => m.ProjectId, o => o.Ignore())
            .ForMember(m => m.CreatedAt, o => o.MapFrom(s => s.Commit.Author.Date))
            .ForMember(m => m.From, o => o.MapFrom(s => s.Commit.Author.Date))
            .ForMember(m => m.To, o => o.MapFrom(s => s.Commit.Author.Date))
            .ForMember(m => m.Description, o => o.MapFrom(s => s.Commit.Message));
        }
Пример #32
0
        private static void LoadStandardMappings(IMapperConfiguration mapperConfiguration, IEnumerable<Type> types)
        {
            var maps = types
                .SelectMany(t => t.GetInterfaces(), (t, i) => new { t, i })
                .Where(type => type.i.IsGenericType &&
                               type.i.GetGenericTypeDefinition() == typeof(IMapFrom<>) &&
                               !type.t.IsAbstract &&
                               !type.t.IsInterface)
                .Select(type => new { Source = type.i.GetGenericArguments()[0], Destination = type.t });

            foreach (var map in maps)
            {
                mapperConfiguration.CreateMap(map.Source, map.Destination);
                mapperConfiguration.CreateMap(map.Destination, map.Source);
            }
        }
Пример #33
0
 public void CreateMappings(IMapperConfiguration configuration)
 {
     configuration.CreateMap <User, UserViewModel>()
     .ForMember(m => m.ExternalTenant, opt => opt.MapFrom(e => new SelectList()
     {
         SelectedValue = e.ExternalTenantCode
     }))
     .ForMember(m => m.AuditHistory, opt => opt.MapFrom(e => new AuditModel()
     {
         AuditableEntity = e
     }))
     .Ignore(m => m.Password);
     configuration.CreateMap <UserViewModel, User>()
     .ForMember(e => e.Password, opt => opt.MapFrom(m => !string.IsNullOrEmpty(m.Password) ? m.Password.Encrypt() : null))
     .ForMember(e => e.ExternalTenantCode, opt => opt.MapFrom(m => m.ExternalTenant.SelectedValue))
     .Ignore(e => e.ExternalTenant);
 }
Пример #34
0
        private static void LoadReverseMappings(IEnumerable<Type> types, IMapperConfiguration mapperConfiguration)
        {
            var maps = types
                .Where(t => !t.IsInterface && !t.IsAbstract && t.GetInterfaces()
                    .Any(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IMapTo<>)))
                .Select(t => new
                {
                    Source = t,
                    Destination = t.GetInterfaces()
                                .Where(i => i.GetGenericTypeDefinition() == typeof(IMapTo<>))
                                .FirstOrDefault()
                                .GetGenericArguments()[0]
                })
                .ToList();

            maps.ForEach(m => mapperConfiguration.CreateMap(m.Source, m.Destination));
        }
        public void CreateMappings(IMapperConfiguration configuration)
        {
            configuration.CreateMap <Comment, CommentDetailsViewModel>()
            .ForMember(
                c => c.Author,
                opt => opt.MapFrom(c => c.Author.UserName));

            configuration.CreateMap <Comment, CommentDetailsViewModel>()
            .ForMember(
                c => c.AuthorAvatar,
                opt => opt.MapFrom(c => c.Author.Avatar));

            configuration.CreateMap <Comment, CommentDetailsViewModel>()
            .ForMember(
                c => c.IsRoot,
                opt => opt.MapFrom(c => c.ParentCommentID == null));
        }
Пример #36
0
        public void CreateMappings(IMapperConfiguration configuration)
        {
            configuration.CreateMap <Recipe, RecipeViewModel>()
            .ForMember(x => x.AuthorId, opt => opt.MapFrom(x => x.AuthorId));

            configuration.CreateMap <Recipe, RecipeViewModel>()
            .ForMember(x => x.Author, opt => opt.MapFrom(x => (x.Author.FirstName + " " + x.Author.LastName)));

            configuration.CreateMap <Recipe, RecipeViewModel>()
            .ForMember(x => x.Occasion, opt => opt.MapFrom(x => x.Occasion.Name));

            configuration.CreateMap <Recipe, RecipeViewModel>()
            .ForMember(x => x.CountLikes, opt => opt.MapFrom(x => x.Likes.Any() ? x.Likes.Sum(v => (int)v.Value) : 0));

            configuration.CreateMap <Recipe, RecipeViewModel>()
            .ForMember(x => x.CountComments, opt => opt.MapFrom(x => (x.Comments.Count() - 1)));
        }
Пример #37
0
        private static void MapProperties(PropertyMapInfo propMapInfo, IMapperConfiguration mapperConfiguration)
        {
            var sourceType              = propMapInfo.SourceType;
            var sourceProperty          = propMapInfo.SourcePropertyInfos;
            var destinationType         = propMapInfo.DestinationType;
            var destinationPropertyInfo = propMapInfo.DestinationPropertyInfo;

            var createMapMethod = mapperConfiguration == null?GenericCreateMapStaticApi.MakeGenericMethod(sourceType, destinationType) : GenericCreateMap.MakeGenericMethod(sourceType, destinationType);

            var mapObject           = createMapMethod.Invoke(mapperConfiguration ?? null, new object[] {});
            var mapObjectExpression = Expression.Constant(mapObject);

            var sourceParameter      = Expression.Parameter(sourceType);
            var destinationParameter = Expression.Parameter(destinationType);

            var destinationMember = Expression.Lambda(
                Expression.Convert(
                    Expression.Property(destinationParameter, destinationPropertyInfo),
                    typeof(object)
                    ),
                destinationParameter
                );

            var memberConfigType          = typeof(IMemberConfigurationExpression <>).MakeGenericType(sourceType);
            var memberConfigTypeParameter = Expression.Parameter(memberConfigType);

            var finalPropertyType  = sourceProperty.Last().PropertyType;
            var propertyExpression = sourceProperty.Aggregate <PropertyInfo, Expression>(null, (current, prop) => current == null ? Expression.Property(sourceParameter, prop) : Expression.Property(current, prop));

            var memberOptions = Expression.Call(memberConfigTypeParameter,
                                                nameof(IMemberConfigurationExpression <object> .MapFrom),
                                                new Type[] { finalPropertyType },
                                                Expression.Lambda(
                                                    propertyExpression,
                                                    sourceParameter
                                                    ));

            var forMemberMethod = Expression.Call(mapObjectExpression,
                                                  nameof(IMappingExpression.ForMember),
                                                  Type.EmptyTypes,
                                                  destinationMember,
                                                  Expression.Lambda(memberOptions, memberConfigTypeParameter));

            Expression.Lambda(forMemberMethod).Compile().DynamicInvoke();
        }
Пример #38
0
        public static void ConfigureMaps(IMapperConfiguration cfg)
        {
            cfg.CreateMap<AuthLoginRequest, AuthLoginInfoPoco>()
            .ForMember(s => s.PlainPassword, m => m.MapFrom(s => s.PlainPassword))
            .ForMember(s => s.UserName, m => m.MapFrom(s => s.UserName));

              cfg.CreateMap<AuthLoginInfoPoco, AuthLoginRequest>()
            .ForMember(s => s.PlainPassword, m => m.MapFrom(s => s.PlainPassword))
            .ForMember(s => s.UserName, m => m.MapFrom(s => s.UserName));

              cfg.CreateMap<AuthLoginResponse, AuthLoginRequest>()
            .ForMember(s => s.UserName, m => m.MapFrom(s => s.UserName))
            .ForMember(s => s.PlainPassword, m => m.MapFrom(s => s.PlainPassword));

              cfg.CreateMap<AuthLoginRequest, AuthLoginResponse>()
            .ForMember(s => s.UserName, m => m.MapFrom(s => s.UserName))
            .ForMember(s => s.PlainPassword, m => m.MapFrom(s => s.PlainPassword));
        }
Пример #39
0
        private static void ApplyMapping(IMapperConfiguration cfg, bool isArabic)
        {
            cfg.CreateMap <Asset, AssetViewModel>()
            .ForMember(e => e.ZoneName, opt => opt.MapFrom(f => isArabic ? f.Zone.NameAr : f.Zone.NameEn))

            .ForMember(e => e.ModelName, opt => opt.MapFrom(f => isArabic ? f.AssetModel.NameAr : f.AssetModel.NameEn))
            .ForMember(e => e.LocationId, opt => opt.MapFrom(f => f.Zone.LocationId)).ReverseMap();

            cfg.CreateMap <Location, LocationViewModel>().ForMember(e => e.Name, opt => opt.MapFrom(f => isArabic ? f.NameAr : f.NameEn)).ReverseMap();

            cfg.CreateMap <AssetModel, AssetModelViewModel>().ForMember(e => e.Name, opt => opt.MapFrom(f => isArabic ? f.NameAr : f.NameEn)).ReverseMap();



            cfg.CreateMap <Zone, ZoneViewModel>()
            .ForMember(e => e.LocationName, opt => opt.MapFrom(f => isArabic ? f.Location.NameAr : f.Location.NameEn))
            .ForMember(e => e.Name, opt => opt.MapFrom(f => isArabic ? f.NameAr : f.NameEn)).ReverseMap();
        }
Пример #40
0
    }     //end ReverseMapWithForMemberPreserved41

    public static IMappingExpression <TDestination, TSource> ReverseMapWithForMemberPreserved <TSource, TDestination>
        (this IMappingExpression <TSource, TDestination> expression, IMapperConfiguration cfg)
    {
        var reversedMapping = cfg.CreateMap <TDestination, TSource>();

        foreach (var map in expression.TypeMap.GetPropertyMaps())
        {
            var newDestionationName = map.SourceMember.Name;
            var newDestinationType  = typeof(TSource).GetProperties().Single(p => p.Name == newDestionationName).PropertyType;
            var newSourceName       = map.DestinationProperty.Name;
            var newSourceType       = typeof(TDestination).GetProperties().Single(p => p.Name == newSourceName).PropertyType;
            var newSourceTypeCode   = System.Type.GetTypeCode(newSourceType);

            //if the names already match AM will handle so just let it do its thing
            if (newSourceName == newDestionationName)
            {
                continue;
            }

            //generic lists and collections not supported, you'll need to map
            //manually on the reverse side (but only if their names don't match)
            if (newSourceType.IsGenericType)
            {
                continue;
            }

            ////types must be of the same kind
            if ((newSourceType.IsValueType && !newDestinationType.IsValueType) ||
                (!newSourceType.IsValueType && newDestinationType.IsValueType))
            {
                continue;
            }

            if (newSourceType.IsValueType)
            {
                reversedMapping.ForMember(newDestionationName, o => o.UseValue(map.UseDestinationValue));
            }
            else
            {
                reversedMapping.ForMember(newDestionationName, o => o.MapFrom <Object>(newSourceName));
            }
        } //end of foreach GetPropertyMaps() block
        return(reversedMapping);
    }     //end ReverseMapWithForMemberPreserved
 public void Initialize(IMapperConfiguration config)
 {
     config.CreateMap <TournamentDto, IndexViewModel>();
     config.CreateMap <TournamentDto, GetDetailViewModel>();
     config.CreateMap <RegisterViewModel, RegistrationDto>()
     .ConvertUsing(src => Mapper.Map <RegistrationDto>(src.Registration))
     ;
     config.CreateMap <_RegistrationViewModel, RegistrationDto>()
     .BeforeMap((src, dest) =>
     {
         src.Registrants = src.Registrants
                           .Where(i => string.IsNullOrWhiteSpace(i.FirstName) == false &&
                                  string.IsNullOrWhiteSpace(i.LastName) == false)
                           .ToList();
     })
     .ForMember(dest => dest.Club, opts => opts.MapFrom(src => new ClubDto
     {
         ClubId = src.ClubId,
     }));
     ;
     config.CreateMap <_RegistrationViewModel.RegistrantViewModel, RegistrantDto>()
     .ForMember(dest => dest.Divisions, opts => opts.MapFrom(src => src.SelectedDivisionIds.Select(i => new DivisionDto
     {
         DivisionId = i
     })))
     ;
     config.CreateMap <RegistrationDto, ConfirmViewModel>()
     .ForMember(dest => dest.ClubName, opts => opts.MapFrom(src => src.Club.Name))
     ;
     config.CreateMap <RegistrantDto, ConfirmViewModel.RegistrantViewModel>()
     .ForMember(dest => dest.DivisionName, opts => opts.MapFrom(src => src.Divisions.First().Name))
     ;
     config.CreateMap <RegistrationDto, EditViewModel>()
     .ForMember(dest => dest.Registration, opts => opts.MapFrom(src => src))
     ;
     config.CreateMap <RegistrationDto, _RegistrationViewModel>()
     .ForMember(dest => dest.ClubId, opts => opts.MapFrom(src => src.Club.ClubId))
     ;
     config.CreateMap <RegistrantDto, _RegistrationViewModel.RegistrantViewModel>()
     .ForMember(dest => dest.SelectedDivisionIds, opts => opts.ResolveUsing(src => src.Divisions.Select(i => i.DivisionId)))
     .ForMember(dest => dest.Divisions, opts => opts.Ignore())
     ;
 }
Пример #42
0
        private void AutoMapperConfig(IMapperConfiguration config)
        {
            var assembly        = typeof(CapstoneEntities).Assembly;
            var entityInterface = typeof(IEntity);

            var entityTypes = assembly.DefinedTypes.Where(q => entityInterface.IsAssignableFrom(q));

            foreach (var entityType in entityTypes)
            {
                var name          = entityType.Name;
                var viewModelType = assembly.DefinedTypes.FirstOrDefault(q => q.Name == (name + "ViewModel"));

                if (viewModelType != null)
                {
                    config.CreateMap(entityType, viewModelType);
                    config.CreateMap(viewModelType, entityType);
                }
            }
        }
 private static void ClubMapping(IMapperConfiguration cfg)
 {
     cfg.CreateMap <ClubEntity, Club>()
     .ForMember(
         dest => dest.Name,
         opts => opts.MapFrom(src => src.Naam))
     .ForMember(
         dest => dest.Active,
         opts => opts.MapFrom(src => src.Actief))
     .ForMember(
         dest => dest.Shower,
         opts => opts.MapFrom(src => src.Douche == 1))
     .ForMember(
         dest => dest.MainLocation,
         opts => opts.MapFrom(src => CreateMainClubLocation(src.Lokalen)))
     .ForMember(
         dest => dest.AlternativeLocations,
         opts => opts.MapFrom(src => CreateSecundaryClubLocations(src.Lokalen)));
 }
Пример #44
0
 public void CreateMappings(IMapperConfiguration configuration)
 {
     configuration.CreateMap <Comment, CommentViewModel>()
     .ForMember(c => c.Author, config => config.MapFrom(c => c.Author.UserName));
     configuration.CreateMap <Comment, CommentViewModel>()
     .ForMember(c => c.AuthorPictureUrl, config => config.MapFrom(c => c.Author.PictureUrl));
     configuration.CreateMap <Comment, CommentViewModel>()
     .ForMember(c => c.ReportsCount, config => config.MapFrom(c => c.Reports.Count(r => !r.IsDeleted)));
     configuration.CreateMap <Comment, CommentViewModel>()
     .ForMember(c => c.LikesCount, config => config.MapFrom(c => c.Likes.Count(l => !l.IsDeleted)));
     configuration.CreateMap <Comment, CommentViewModel>()
     .ForMember(c => c.Post, config => config.MapFrom(c => c.Answer.Post.Title));
     configuration.CreateMap <Comment, CommentViewModel>()
     .ForMember(c => c.PostId, config => config.MapFrom(c => c.Answer.PostId));
     configuration.CreateMap <Comment, CommentViewModel>()
     .ForMember(c => c.IsPostLocked, config => config.MapFrom(c => c.Answer.Post.IsLocked));
     configuration.CreateMap <Comment, CommentViewModel>()
     .ForMember(c => c.PostAuthor, config => config.MapFrom(c => c.Answer.Post.Author.UserName));
     configuration.CreateMap <Comment, CommentViewModel>()
     .ForMember(c => c.PostAuthorId, config => config.MapFrom(c => c.Answer.Post.AuthorId));
 }
Пример #45
0
 public void CreateMappings(IMapperConfiguration configuration)
 {
     configuration.CreateMap <HotelRoom, HotelRoomViewModel>()
     .ForMember(m => m.RoomType, opt => opt.MapFrom(m => m.Room.Type))
     .ForMember(m => m.RoomId, opt => opt.MapFrom(m => m.Room.Id))
     .ForMember(m => m.Description, opt => opt.MapFrom(m => m.Room.Description))
     .ForMember(m => m.Price, opt => opt.MapFrom(m => m.Room.Price))
     .ForMember(m => m.Size, opt => opt.MapFrom(m => m.Room.Size))
     .ForMember(m => m.Capacity, opt => opt.MapFrom(m => m.Room.Capacity))
     .ForMember(m => m.AirConditioning, opt => opt.MapFrom(m => m.Room.AirConditioning))
     .ForMember(m => m.Balcom, opt => opt.MapFrom(m => m.Room.Balcon))
     .ForMember(m => m.Bathroom, opt => opt.MapFrom(m => m.Room.Bathroom))
     .ForMember(m => m.FreeWiFi, opt => opt.MapFrom(m => m.Room.FreeWiFi))
     .ForMember(m => m.HairDryer, opt => opt.MapFrom(m => m.Room.HairDryer))
     .ForMember(m => m.Heating, opt => opt.MapFrom(m => m.Room.Heating))
     .ForMember(m => m.Iron, opt => opt.MapFrom(m => m.Room.Iron))
     .ForMember(m => m.Telephone, opt => opt.MapFrom(m => m.Room.Telephone))
     .ForMember(m => m.TV, opt => opt.MapFrom(m => m.Room.TV))
     .ForMember(m => m.Beds, opt => opt.MapFrom(m => m.Room.BedOptions))
     .ForMember(m => m.Images, opt => opt.MapFrom(m => m.Room.PhotosSource.Select(i => i.Source)));
 }
Пример #46
0
        /// <summary>
        /// Set up any requested assocaiated mappings
        /// </summary>
        private bool SetupAllAssociatedMappings(IMapperConfiguration cfg, bool readFromDatabase)
        {
            var shouldDecompile = false;

            if (AssociatedDtoMapping != null)
            {
                shouldDecompile |= CheckAndSetupAssociatedMapping(AssociatedDtoMapping, cfg, readFromDatabase);
            }

            if (AssociatedDtoMappings == null)
            {
                return(shouldDecompile);
            }

            foreach (var associatedDtoMapping in AssociatedDtoMappings)
            {
                shouldDecompile |= CheckAndSetupAssociatedMapping(associatedDtoMapping, cfg, readFromDatabase);
            }

            return(shouldDecompile);
        }
Пример #47
0
        private void AutoMapperConfig(IMapperConfiguration config)
        {
            var assembly        = typeof(DSSEntities).Assembly;
            var entityInterface = typeof(IEntity);

            var entityTypes = assembly.DefinedTypes.Where(q => entityInterface.IsAssignableFrom(q));

            foreach (var entityType in entityTypes)
            {
                var name          = entityType.Name;
                var viewModelType = assembly.DefinedTypes.FirstOrDefault(q => q.Name == (name + "ViewModel"));

                if (viewModelType != null)
                {
                    config.CreateMap(entityType, viewModelType);
                    config.CreateMap(viewModelType, entityType);
                }
            }

            //config.CreateMap<PublisherUser, PublisherUserEditViewModel>()
            //    .ForMember(q => q.AspNetUser, opt => opt.MapFrom(q => q.AspNetUser))
            //    .ForMember(q => q.Brand, opt => opt.MapFrom(q => q.Brand));

            //config.CreateMap<PublisherUserEditViewModel, PublisherUser>()
            //    .ForMember(q => q.AspNetUser, opt => opt.MapFrom(q => q.AspNetUser))
            //    .ForMember(q => q.Brand, opt => opt.MapFrom(q => q.Brand));

            //config.CreateMap<Location, LocationEditViewModel>()
            //    .ForMember(q => q.LandingPagePlaces, opt => opt.MapFrom(q => q.LandingPagePlaces));

            //config.CreateMap<AspNetUser, AspNetUserEditViewModel>()
            //   .ForMember(q => q.AspNetRoles, opt => opt.MapFrom(q => q.AspNetRoles));

            //config.CreateMap<UserAccount, UserAccountViewModel>();

            //config.CreateMap<UserAccountCreateViewModel, UserAccount>();

            config.CreateMap <Playlist, PlaylistDetailVM>()
            .ForMember(a => a.Duration, opt => opt.MapFrom(a => "00:00:00"));
        }
Пример #48
0
        void CreateMaps(IMapperConfiguration config)
        {
            config.CreateMap <CodeCampUser, CodeCampUserViewModel>()
            .ReverseMap();

            config.CreateMap <Speaker, Speaker>()
            .ForMember(m => m.Id, opt => opt.Ignore())
            .ForMember(m => m.Talks, opt => opt.Ignore())
            .ForMember(m => m.Event, opt => opt.Ignore())
            .ForMember(m => m.UserName, opt => opt.Ignore());

            config.CreateMap <SpeakerViewModel, Speaker>()
            .ForMember(m => m.Talks, opt => opt.Ignore());
            config.CreateMap <Speaker, SpeakerViewModel>()
            .ForMember(m => m.Talks, opt => opt.Ignore())
            .ForMember(m => m.SpeakerLink, opt => opt.MapFrom(s => s.Event == null ? "" : $"/{s.Event.Moniker}/Speakers/{s.Name.Replace(" ", "-")}"))
            .ForMember(m => m.Email, opt => opt.MapFrom(s => s.UserName));

            config.CreateMap <Talk, TalkViewModel>()
            .ForMember(m => m.Room, opt => opt.MapFrom(t => t.Room.Name))
            .ForMember(m => m.Time, opt => opt.MapFrom(t => t.TimeSlot.Time))
            .ForMember(m => m.Track, opt => opt.MapFrom(t => t.Track.Name));

            config.CreateMap <TalkViewModel, Talk>()
            .ForMember(m => m.Room, opt => opt.Ignore())
            .ForMember(m => m.TimeSlot, opt => opt.Ignore())
            .ForMember(m => m.Track, opt => opt.Ignore());

            config.CreateMap <Sponsor, SponsorViewModel>().ReverseMap();

            config.CreateMap <Talk, FavoriteTalkViewModel>()
            .ForMember(dest => dest.Room, opt => opt.MapFrom(s => s.Room.Name))
            .ForMember(dest => dest.Time, opt => opt.MapFrom(s => s.TimeSlot.Time))
            .ForMember(dest => dest.SpeakerName, opt => opt.MapFrom(s => s.Speaker.Name))
            .ForMember(dest => dest.Title, opt => opt.MapFrom(s => s.Title))
            .ForMember(dest => dest.Abstract, opt => opt.MapFrom(s => s.Abstract));

            config.CreateMap <EventInfo, EventInfoViewModel>().ReverseMap();
            config.CreateMap <EventLocation, EventLocationViewModel>().ReverseMap();
        }
Пример #49
0
        public static void ConfigureMapper(IMapperConfiguration config)
        {
            config.CreateMap <Product, ProductViewModel>()
            .ConvertUsing <ProductToVmConverter>();

            config.CreateMap <ProductDto, ProductViewModel>()
            .ConvertUsing <ProductDtoVmConverter>();

            config.CreateMap <SalesRecordDto, SalesRecordViewModel>()
            .ConvertUsing <SalesReccordDtoVmConverter>();

            config.CreateMap <OrderDetailDto, SalesRecordViewModel>()
            .ConvertUsing <OrderDetailDtoSalesVmConverter>();

            config.CreateMap <OrderDetailDto, OrderDetailViewModel>()
            .ConvertUsing <OrderDetailDtoVmConverter>();

            config.CreateMap <GetCategoryDto, CategoryViewModel>()
            .ConvertUsing <GetCategoryDtoVmConverter>();


            config.CreateMap <OrderDetail, OrderDetailViewModel>()
            .ConvertUsing <OrderDetailVmConverter>();

            config.CreateMap <FaultyProductsDto, SpoilViewModel>()
            .ConvertUsing <FaultyProductDtoSpoilVmConverter>();

            config.CreateMap <AuditDto, AuditViewModel>()
            .ConvertUsing <AuditDtoVmConverter>();

            config.CreateMap <AccountDto, AppUserViewModel>()
            .ConvertUsing <AccountDtoToAppUserVmConverter>();

            config.CreateMap <AppUser, AppUserViewModel>()
            .ConvertUsing <AppUserToAppUserVmConverter>();

            config.CreateMap <OrderDetailSalesHistoryDto, OrderDetailViewModel>()
            .ConvertUsing <OrderDetailSalesHistoryDtoConverter>();
        }
Пример #50
0
        public void CreateMappings(IMapperConfiguration configuration)
        {
            configuration.CreateMap <Article, ArticleDetailsViewModel>()
            .ForMember(
                a => a.Author,
                opt => opt.MapFrom(a => a.Author.UserName));

            configuration.CreateMap <Article, ArticleDetailsViewModel>()
            .ForMember(
                c => c.Category,
                opt => opt.MapFrom(a => a.Category.Name));

            configuration.CreateMap <Article, ArticleDetailsViewModel>()
            .ForMember(
                v => v.Votes,
                opt => opt.MapFrom(a => a.Votes.Where(v => v.ArticleId == a.Id).Any() ? a.Votes.Where(v => v.ArticleId == a.Id).Sum(v => (int)v.VoteType) : 0));

            configuration.CreateMap <Article, ArticleDetailsViewModel>()
            .ForMember(
                c => c.TotalComments,
                opt => opt.MapFrom(a => a.Comments.Where(c => c.ArticleId == a.Id).Any() ? a.Comments.Where(c => c.ArticleId == a.Id).Count() : 0));
        }
Пример #51
0
 public void ConfigureMapping(IMapperConfiguration config)
 {
     config.CreateMap<MenuEntity, MenuDto>();
     config.CreateMap<MenuItemEntity, MenuItemDto>().ForMember(t => t.Caption, expression => expression.MapFrom(t => t.Title));
 }
Пример #52
0
 public MappingsLoader(IMapperConfiguration config, Func<Type, object> locate)
 {
     this.Config = config;
     this.Locate = locate;
 }
        private static void MatchMapping(IMapperConfiguration cfg)
        {
            cfg.CreateMap<MatchEntity, OtherMatch>()
                .ForMember(
                    dest => dest.Home,
                    opts => opts.MapFrom(src => new OpposingTeam
                    {
                        ClubId = src.HomeClubId,
                        TeamCode = src.HomeTeamCode
                    }))
                .ForMember(
                    dest => dest.Away,
                    opts => opts.MapFrom(src => new OpposingTeam
                    {
                        ClubId = src.AwayClubId,
                        TeamCode = src.AwayTeamCode
                    }))
                .ForMember(
                    dest => dest.IsPlayed,
                    opts => opts.MapFrom(src =>
                        GetScoreType(src) != MatchOutcome.NotYetPlayed &&
                        GetScoreType(src) != MatchOutcome.BeingPlayed))
                .ForMember(
                    dest => dest.ScoreType,
                    opts => opts.MapFrom(src => GetScoreType(src)))
                .ForMember(
                    dest => dest.Score,
                    opts => opts.MapFrom(src => !src.WalkOver && src.HomeScore.HasValue ? new MatchScore(src.HomeScore.Value, src.AwayScore.Value) : null))

                .AfterMap((matchEntity, match) =>
                {
                    //SetMatchPlayerAliases(match);
                    //ChangeMeaningOfHomePlayer(match);
                    SetIndividualMatchesOutcome(match.Games, null);
                });

            cfg.CreateMap<MatchEntity, Match>()
                .ForMember(
                    dest => dest.TeamId,
                    opts => opts.MapFrom(src => src.HomeTeamId.HasValue ? src.HomeTeamId : src.AwayTeamId))
                .ForMember(
                    dest => dest.Opponent,
                    opts => opts.MapFrom(src => new OpposingTeam
                    {
                        ClubId = src.HomeTeamId.HasValue ? src.AwayClubId : src.HomeClubId,
                        TeamCode = src.HomeTeamId.HasValue ? src.AwayTeamCode : src.HomeTeamCode
                    }))
                .ForMember(
                    dest => dest.IsPlayed,
                    opts => opts.MapFrom(src =>
                        GetScoreType(src) != MatchOutcome.NotYetPlayed &&
                        GetScoreType(src) != MatchOutcome.BeingPlayed))
                .ForMember(
                    dest => dest.ScoreType,
                    opts => opts.MapFrom(src => GetScoreType(src)))
                .ForMember(
                    dest => dest.Score,
                    opts => opts.MapFrom(src => !src.WalkOver && src.HomeScore.HasValue ? new MatchScore(src.HomeScore.Value, src.AwayScore.Value) : null))

                .AfterMap((matchEntity, match) =>
                {
                    SetMatchPlayerAliases(match);
                    ChangeMeaningOfHomePlayer(match);
                    SetIndividualMatchesOutcome(match.Games, match.IsHomeMatch);
                });
        }
 private static void ConfigureModelToDto(IMapperConfiguration cfg)
 {
     cfg.CreateMap<User, UserDto>();
     cfg.CreateMap<UserBlog, UserBlogDto>();
 }
 private static void ConfigureDtoToModel(IMapperConfiguration cfg)
 {
     cfg.CreateMap<UserDto, User>();
     cfg.CreateMap<UserBlogDto, UserBlog>();
 }
 private static void ConfigureMaps(IMapperConfiguration cfg)
 {
     ConfigureModelToDto(cfg);
     ConfigureDtoToModel(cfg);
 }
Пример #57
0
 public void CreateMappings(IMapperConfiguration configuration)
 {
     configuration.CreateMap<Test, TestDetailsModel>()
         .ForMember(x => x.Author, opt => opt.MapFrom(x => x.User.UserName));
 }
Пример #58
0
 public static void ConfigureMaps(IMapperConfiguration cfg)
 {
 }
 private static void PlayerMapping(IMapperConfiguration cfg, KlassementValueConverter klassementToValueConverter)
 {
     cfg.CreateMap<PlayerEntity, Player>()
         .ForMember(
             dest => dest.Name,
             opts => opts.MapFrom(src => src.Naam))
         .ForMember(
             dest => dest.Alias,
             opts => opts.MapFrom(src => src.NaamKort))
         .ForMember(
             dest => dest.Active,
             opts => opts.MapFrom(src => !src.IsGestopt))
         .ForMember(
             dest => dest.QuitYear,
             opts => opts.MapFrom(src => src.Gestopt))
         .ForMember(
             dest => dest.Security,
             opts => opts.MapFrom(src => src.Toegang.ToString()))
         .ForMember(
             dest => dest.Style,
             opts => opts.MapFrom(src => new PlayerStyle(src.Id, src.Stijl, src.BesteSlag)))
         .ForMember(
             dest => dest.Contact,
             opts => opts.MapFrom(src => new PlayerContact(src.Id, src.Email, src.Gsm, src.Adres, src.Gemeente)))
         .ForMember(
             dest => dest.Vttl,
             opts => opts.MapFrom(src => src.ClubIdVttl.HasValue ?
                 CreateVttlPlayer(klassementToValueConverter, src.ClubIdVttl.Value, src.ComputerNummerVttl.Value, src.LinkKaartVttl, src.KlassementVttl, src.VolgnummerVttl.Value, src.IndexVttl.Value)
                 : null))
         .ForMember(
             dest => dest.Sporta,
             opts => opts.MapFrom(src => src.ClubIdSporta.HasValue ?
                 CreateSportaPlayer(klassementToValueConverter, src.ClubIdSporta.Value, src.LidNummerSporta.Value, src.LinkKaartSporta, src.KlassementSporta, src.VolgnummerSporta.Value, src.IndexSporta.Value)
                 : null))
         ;
 }
 private static void ClubMapping(IMapperConfiguration cfg)
 {
     cfg.CreateMap<ClubEntity, Club>()
         .ForMember(
             dest => dest.Name,
             opts => opts.MapFrom(src => src.Naam))
         .ForMember(
             dest => dest.Active,
             opts => opts.MapFrom(src => src.Actief))
         .ForMember(
             dest => dest.Shower,
             opts => opts.MapFrom(src => src.Douche == 1))
         .ForMember(
             dest => dest.MainLocation,
             opts => opts.MapFrom(src => CreateMainClubLocation(src.Lokalen)))
         .ForMember(
             dest => dest.AlternativeLocations,
             opts => opts.MapFrom(src => CreateSecundaryClubLocations(src.Lokalen)));
 }