Esempio n. 1
0
        private void configureForTrees()
        {
            CreateMap <Trip, ImportTreesModel>()
            .ForMember(dest => dest.Sites, opt => opt.MapFrom(src => src.Sites));

            CreateMap <Site, ImportSiteTreesModel>();

            CreateMap <TreeBase, ImportTreeModel>()
            .ForMember(dest => dest.IsEditing, opt => opt.MapFrom(src =>
                                                                  !ValidationMapper.Map <TreeBase, ImportTreeModel>(src.Validate(ValidationTag.Required)).IsValid()))
            .ForMember(dest => dest.IsRemovable, opt => opt.MapFrom(src => src.Site.Trees.Count > 1))
            .ForMember(dest => dest.Photos, opt => opt.MapFrom(src => Mapper.Map <TreeBase, ImportTreePhotoGalleryModel>(src)))
            .ForMember(dest => dest.Coordinates, opt => opt.MapFrom(src => Mapper.Map <TreeBase, CoordinatePickerModel>(src)));
            ValidationMapper.CreateMap <TreeBase, ImportTreeModel>()
            .ForPath("*.InputFormat", "*").ForPath("*.Feet", "*").ForPath("*.Latitude.*", "*").ForPath("*.Longitude.*", "*");

            CreateMap <ImportTreesModel, Trip>().ForMember(dest => dest.Sites, opt => opt.Ignore())
            .AfterMap((src, dest) => src.Sites.ForEach(s => Mapper.Map(s, dest.FindSiteById(s.Id))));

            CreateMap <ImportSiteTreesModel, Site>().ForMember(dest => dest.Trees, opt => opt.Ignore())
            .AfterMap((src, dest) => src.Trees.ForEach(t => Mapper.Map(t, dest.FindTreeById(t.Id))));

            CreateMap <ImportTreeModel, TreeBase>()
            .ForMember(dest => dest.Photos, opt => opt.Ignore());
        }
Esempio n. 2
0
        protected override void Configure()
        {
            CreateMap <Model.Imports.TreeBase, ImportTreePhotoGalleryModel>()
            .ForMember(dest => dest.TreeId, opt => opt.MapFrom(src => src.Id))
            .ForMember(dest => dest.TripId, opt => opt.MapFrom(src => src.Site.Trip.Id));
            ValidationMapper.CreateMap <Model.Imports.TreeBase, PhotoGalleryModel>()
            .IgnorePath("*").ForPath("Photo*", "AddPhotoActionName");

            CreateMap <Model.Imports.Site, ImportSitePhotoGalleryModel>()
            .ForMember(dest => dest.SiteId, opt => opt.MapFrom(src => src.Id))
            .ForMember(dest => dest.TripId, opt => opt.MapFrom(src => src.Trip.Id));
            ValidationMapper.CreateMap <Model.Imports.Site, PhotoGalleryModel>()
            .IgnorePath("*").ForPath("Photo*", "AddPhotoActionName");

            CreateMap <PhotoReferenceBase, PhotoCaptionModel>()
            .Include <TreeMeasurementPhotoReference, TreePhotoCaptionModel>()
            .Include <SiteVisitPhotoReference, SitePhotoCaptionModel>()
            .Include <TreePhotoReference, TreePhotoCaptionModel>()
            .Include <SitePhotoReference, SitePhotoCaptionModel>()
            .Include <Model.Imports.SitePhotoReference, EmptyContextPhotoCaptionModel>()
            .Include <Model.Imports.TreePhotoReference, EmptyContextPhotoCaptionModel>();

            CreateMap <TreeMeasurementPhotoReference, TreePhotoCaptionModel>()
            .ForMember(dest => dest.BotanicalName, opt => opt.MapFrom(src => src.TreeMeasurement.ScientificName))
            .ForMember(dest => dest.TreeId, opt => opt.MapFrom(src => src.TreeMeasurement.Tree.Id))
            .ForMember(dest => dest.SiteName, opt => opt.MapFrom(src => src.TreeMeasurement.Tree.Site.Name))
            .ForMember(dest => dest.SiteId, opt => opt.MapFrom(src => src.TreeMeasurement.Tree.Site.Id))
            .ForMember(dest => dest.StateName, opt => opt.MapFrom(src => src.TreeMeasurement.Tree.Site.State.Name))
            .ForMember(dest => dest.StateId, opt => opt.MapFrom(src => src.TreeMeasurement.Tree.Site.State.Id));

            CreateMap <TreePhotoReference, TreePhotoCaptionModel>()
            .ForMember(dest => dest.BotanicalName, opt => opt.MapFrom(src => src.Tree.ScientificName))
            .ForMember(dest => dest.TreeId, opt => opt.MapFrom(src => src.Tree.Id))
            .ForMember(dest => dest.SiteName, opt => opt.MapFrom(src => src.Tree.Site.Name))
            .ForMember(dest => dest.SiteId, opt => opt.MapFrom(src => src.Tree.Site.Id))
            .ForMember(dest => dest.StateName, opt => opt.MapFrom(src => src.Tree.Site.State.Name))
            .ForMember(dest => dest.StateId, opt => opt.MapFrom(src => src.Tree.Site.State.Id));

            CreateMap <SiteVisitPhotoReference, SitePhotoCaptionModel>()
            .ForMember(dest => dest.SiteName, opt => opt.MapFrom(src => src.SiteVisit.Site.Name))
            .ForMember(dest => dest.SiteId, opt => opt.MapFrom(src => src.SiteVisit.Site.Id))
            .ForMember(dest => dest.StateName, opt => opt.MapFrom(src => src.SiteVisit.Site.State.Name))
            .ForMember(dest => dest.StateId, opt => opt.MapFrom(src => src.SiteVisit.Site.State.Id));

            CreateMap <SitePhotoReference, SitePhotoCaptionModel>()
            .ForMember(dest => dest.SiteName, opt => opt.MapFrom(src => src.Site.Name))
            .ForMember(dest => dest.SiteId, opt => opt.MapFrom(src => src.Site.Id))
            .ForMember(dest => dest.StateName, opt => opt.MapFrom(src => src.Site.State.Name))
            .ForMember(dest => dest.StateId, opt => opt.MapFrom(src => src.Site.State.Id));

            CreateMap <Model.Imports.SitePhotoReference, EmptyContextPhotoCaptionModel>();
            CreateMap <Model.Imports.TreePhotoReference, EmptyContextPhotoCaptionModel>();
        }
Esempio n. 3
0
 protected override void Configure()
 {
     ValidationMapper.CreateMap <User, AccountRegistrationModel>()
     .ForPath("Password.*", "Password");
     ValidationMapper.CreateMap <User, CompleteAccountPasswordAssistanceModel>()
     .ForPath("Password.*", "Password");
     ValidationMapper.CreateMap <User, AccountEditModel>()
     .ForPath("Password.*", "Password.NewPassword")
     .ForPath("LastName", "Details.Name")
     .ForPath("FirstName", "Details.Name");
     CreateMap <User, AccountEditModel>()
     .ForMember(dest => dest.Details, opt => opt.MapFrom(src => Mapper.Map <User, AccountEditDetailsModel>(src)))
     .ForMember(dest => dest.Password, opt => opt.UseValue(new AccountEditPasswordModel {
     }));
     CreateMap <User, AccountEditDetailsModel>()
     .ForMember(dest => dest.Name, opt => opt.MapFrom(src =>
     {
         return(!string.IsNullOrWhiteSpace(src.Firstname) && !string.IsNullOrWhiteSpace(src.Lastname) ?
                string.Format("{1}, {0}", src.Firstname, src.Lastname) :
                string.Empty);
     }));
     CreateMap <AccountEditDetailsModel, User>()
     .ForMember(dest => dest.Firstname, opt => opt.MapFrom(src =>
     {
         if (!string.IsNullOrWhiteSpace(src.Name))
         {
             string[] parts = src.Name.Split(',');
             if (parts.Length > 1)
             {
                 return(parts[1]);
             }
         }
         return(string.Empty);
     }))
     .ForMember(dest => dest.Lastname, opt => opt.MapFrom(src =>
     {
         if (!string.IsNullOrWhiteSpace(src.Name))
         {
             string[] parts = src.Name.Split(',');
             if (parts.Length > 1)
             {
                 return(parts[0]);
             }
         }
         return(string.Empty);
     }));
 }
Esempio n. 4
0
        private void configureForTrip()
        {
            CreateMap <Trip, ImportTripModel>()
            .ForMember(dest => dest.FirstMeasurer, opt => opt.MapFrom(src => src.Measurers.Count > 0 ? src.Measurers[0].ToFormalName() : string.Empty))
            .ForMember(dest => dest.SecondMeasurer, opt => opt.MapFrom(src => src.Measurers.Count > 1 ? src.Measurers[1].ToFormalName() : string.Empty))
            .ForMember(dest => dest.ThirdMeasurer, opt => opt.MapFrom(src => src.Measurers.Count > 2 ? src.Measurers[2].ToFormalName() : string.Empty));
            ValidationMapper.CreateMap <Trip, ImportTripModel>()
            .ForPath("Measurers[0].FirstName", "FirstMeasurer").ForPath("Measurers[0].LastName", "FirstMeasurer").UseMessage("Measurers[0].*", "Name must be in Lastname, Firstname format.")
            .ForPath("Measurers[1].FirstName", "SecondMeasurer").ForPath("Measurers[1].LastName", "SecondMeasurer").UseMessage("Measurers[1].*", "Name must be in Lastname, Firstname format.")
            .ForPath("Measurers[2].FirstName", "ThirdMeasurer").ForPath("Measurers[2].LastName", "ThirdMeasurer").UseMessage("Measurers[2].*", "Name must be in Lastname, Firstname format.")
            .ForPath("Measurers", "FirstMeasurer").UseMessage("Measurers", "Name must be specified.");

            CreateMap <ImportTripModel, Trip>()
            .AfterMap((m, t) =>
            {
                int lastSpecifiedMeasurer = !string.IsNullOrWhiteSpace(m.ThirdMeasurer) ? 3
                            : !string.IsNullOrWhiteSpace(m.SecondMeasurer) ? 2
                            : !string.IsNullOrWhiteSpace(m.FirstMeasurer) ? 1 : 0;
                while (t.Measurers.Count < lastSpecifiedMeasurer)
                {
                    t.Measurers.Add(Name.Null());
                }
                while (t.Measurers.Count > lastSpecifiedMeasurer)
                {
                    t.Measurers.RemoveAt(t.Measurers.Count - 1);
                }
                switch (lastSpecifiedMeasurer)
                {
                case 3: t.Measurers[2] = Name.CreateFromFormalName(m.ThirdMeasurer); goto case 2;

                case 2: t.Measurers[1] = Name.CreateFromFormalName(m.SecondMeasurer); goto case 1;

                case 1: t.Measurers[0] = Name.CreateFromFormalName(m.FirstMeasurer); goto default;

                default: break;
                }
            });
        }