Пример #1
0
            protected override void Configure()
            {
                CreateMap <Activity, ActivityInfo>()
                .ForMember(d => d.Title, o => o.MapFrom(s => s.Values.Title))
                .ForMember(d => d.Content, o => o.MapFrom(s => new HtmlString(s.Values.Content)))
                .ForMember(d => d.StartsOn, o => o.MapFrom(s => s.Values.StartsOn))
                .ForMember(d => d.EndsOn, o => o.MapFrom(s => s.Values.EndsOn))
                .ForMember(d => d.PlaceMarks, o => o.ResolveUsing(s =>
                {
                    var queryProcessor = ServiceProviderLocator.Current.GetService <IProcessQueries>();
                    var placeMarks     = new List <ActivityInfo.PlaceMark>();
                    foreach (var tag in s.Tags.Where(t => t.DomainType != ActivityTagDomainType.Custom))
                    {
                        if (tag.DomainType == ActivityTagDomainType.Place && tag.DomainKey.HasValue)
                        {
                            var place = queryProcessor.Execute(
                                new GetPlaceByIdQuery
                            {
                                Id = tag.DomainKey.Value,
                            }
                                );
                            if (place != null && place.Center != null && place.Center.HasValue)
                            {
                                var placeMark = new ActivityInfo.PlaceMark
                                {
                                    // ReSharper disable PossibleInvalidOperationException
                                    CenterLatitude  = place.Center.Latitude.Value,
                                    CenterLongitude = place.Center.Longitude.Value,
                                    // ReSharper restore PossibleInvalidOperationException
                                    BoundingBox = Mapper.Map <BoundingBoxModel>(place.BoundingBox),
                                    Title       = place.OfficialName,
                                };
                                placeMarks.Add(placeMark);
                            }
                        }
                        else if (tag.DomainType == ActivityTagDomainType.Establishment && tag.DomainKey.HasValue)
                        {
                            var establishment = queryProcessor.Execute(
                                new GetEstablishmentByIdQuery(tag.DomainKey.Value)
                            {
                                EagerLoad = new Expression <Func <Establishment, object> >[]
                                {
                                    e => e.Location,
                                }
                            }
                                );
                            if (establishment != null && establishment.Location.Center != null && establishment.Location.Center.HasValue)
                            {
                                var placeMark = new ActivityInfo.PlaceMark
                                {
                                    // ReSharper disable PossibleInvalidOperationException
                                    CenterLatitude  = establishment.Location.Center.Latitude.Value,
                                    CenterLongitude = establishment.Location.Center.Longitude.Value,
                                    // ReSharper restore PossibleInvalidOperationException
                                    BoundingBox = Mapper.Map <BoundingBoxModel>(establishment.Location.BoundingBox),
                                    Title       = establishment.TranslatedName.Text,
                                };
                                placeMarks.Add(placeMark);
                            }
                        }
                    }
                    return(placeMarks);
                }))
                ;

                CreateMap <ActivityTag, ActivityInfo.Tag>();
                CreateMap <Person, ActivityInfo.OwnedBy>();
            }
Пример #2
0
            protected override void Configure()
            {
                CreateMap<Activity, ActivityInfo>()
                    .ForMember(d => d.Title, o => o.MapFrom(s => s.Values.Title))
                    .ForMember(d => d.Content, o => o.MapFrom(s => new HtmlString(s.Values.Content)))
                    .ForMember(d => d.StartsOn, o => o.MapFrom(s => s.Values.StartsOn))
                    .ForMember(d => d.EndsOn, o => o.MapFrom(s => s.Values.EndsOn))
                    .ForMember(d => d.PlaceMarks, o => o.ResolveUsing(s =>
                    {
                        var queryProcessor = ServiceProviderLocator.Current.GetService<IProcessQueries>();
                        var placeMarks = new List<ActivityInfo.PlaceMark>();
                        foreach (var tag in s.Tags.Where(t => t.DomainType != ActivityTagDomainType.Custom))
                        {
                            if (tag.DomainType == ActivityTagDomainType.Place && tag.DomainKey.HasValue)
                            {
                                var place = queryProcessor.Execute(
                                    new GetPlaceByIdQuery
                                    {
                                        Id = tag.DomainKey.Value,
                                    }
                                );
                                if (place != null && place.Center != null && place.Center.HasValue)
                                {
                                    var placeMark = new ActivityInfo.PlaceMark
                                    {
                                        // ReSharper disable PossibleInvalidOperationException
                                        CenterLatitude = place.Center.Latitude.Value,
                                        CenterLongitude = place.Center.Longitude.Value,
                                        // ReSharper restore PossibleInvalidOperationException
                                        BoundingBox = Mapper.Map<BoundingBoxModel>(place.BoundingBox),
                                        Title = place.OfficialName,
                                    };
                                    placeMarks.Add(placeMark);
                                }
                            }
                            else if (tag.DomainType == ActivityTagDomainType.Establishment && tag.DomainKey.HasValue)
                            {
                                var establishment = queryProcessor.Execute(
                                    new GetEstablishmentByIdQuery(tag.DomainKey.Value)
                                    {
                                        EagerLoad = new Expression<Func<Establishment, object>>[]
                                        {
                                            e => e.Location,
                                        }
                                    }
                                );
                                if (establishment != null && establishment.Location.Center != null && establishment.Location.Center.HasValue)
                                {
                                    var placeMark = new ActivityInfo.PlaceMark
                                    {
                                        // ReSharper disable PossibleInvalidOperationException
                                        CenterLatitude = establishment.Location.Center.Latitude.Value,
                                        CenterLongitude = establishment.Location.Center.Longitude.Value,
                                        // ReSharper restore PossibleInvalidOperationException
                                        BoundingBox = Mapper.Map<BoundingBoxModel>(establishment.Location.BoundingBox),
                                        Title = establishment.TranslatedName.Text,
                                    };
                                    placeMarks.Add(placeMark);
                                }
                            }
                        }
                        return placeMarks;
                    }))
                ;

                CreateMap<ActivityTag, ActivityInfo.Tag>();
                CreateMap<Person, ActivityInfo.OwnedBy>();
            }