Exemplo n.º 1
0
        public async Task <IEnumerable <LocalValidation> > GetLocalValidationsWhereNotUploadedByIdAsync(int validationSessionId)
        {
            ValidationSession validationSession = await GetValidationSessionByIdAsync(validationSessionId);

            return(await Context.LocalValidations.Where(x => x.SampleItem.ValidationSession == validationSession && x.Uploaded == false)
                   .ToListAsync());
        }
Exemplo n.º 2
0
        public async Task <LocalValidation> GetLocalValidationByIdAsync(int id, int validationSessionId)
        {
            ValidationSession validationSession = await GetValidationSessionByIdAsync(validationSessionId);

            return(await Context.LocalValidations.SingleAsync(x =>
                                                              x.SampleItem.Id == id && x.SampleItem.ValidationSession == validationSession));
        }
Exemplo n.º 3
0
        public async Task TryRemoveValidationSessionAsync(int id)
        {
            ValidationSession validationSession = await TryGetValidationSessionByIdAsync(id);

            if (validationSession != null)
            {
                Context.ValidationSessions.Remove(validationSession);
                await SaveChangesAsync();
            }
        }
Exemplo n.º 4
0
        public async Task AddValidationSessionAsync(ValidationSession validationSession)
        {
            await ApiAuthentication.EnsureAuthenticatedAsync();

            int userId = await ApiAuthentication.GetUserIdAsync();

            User user = await Context.Users.SingleAsync(x => x.Id == userId);

            validationSession.User = user;

            await Context.ValidationSessions.AddAsync(validationSession);

            await SaveChangesAsync();
        }
        protected override async Task InitializeOnceAsync(INavigationParameters parameters)
        {
            await base.InitializeOnceAsync(parameters);

            Title = (string)parameters["name"];
            ValidationSessionId = (int)parameters["id"];

            ValidationSession validationSession = await AppDataService.TryGetValidationSessionByIdAsync((int)parameters["id"]);

            if (validationSession != null)
            {
                ViewModel   = Mapper.Map <ValidationSessionDetailViewModel>(validationSession);
                ShowLoading = false;
            }
        }
Exemplo n.º 6
0
        public async Task <LegendItem> GetLegendItemByIdAsync(int id, int validationSessionId)
        {
            ValidationSession validationSession = await GetValidationSessionByIdAsync(validationSessionId);

            return(await Context.LegendItems.SingleAsync(x => x.Id == id && x.ValidationSession == validationSession));
        }
Exemplo n.º 7
0
        protected override async Task InitializeOnceAsync(INavigationParameters parameters)
        {
            await base.InitializeOnceAsync(parameters);

            ValidationSessionId = (int)parameters["id"];
            Title = (string)parameters["name"];

            ValidationSession validationSession = await AppDataService.GetValidationSessionByIdAsync(ValidationSessionId);

            Mapper.Map(validationSession, SamplePointsViewModel);

            if (Connectivity.NetworkAccess == NetworkAccess.Internet)
            {
                // TODO: Localization
                NotificationService.Notify("Synchronizing points...");

                await ApiClient.GetValidationSessionSampleItemsByIdAsync(ValidationSessionId)
                .ContinueWith(async(result) =>
                {
                    Mapper.Map(result.Result, SamplePointsViewModel,
                               opt => opt.Items[nameof(ValidationSession.Id)] = ValidationSessionId);

                    Extent extent = SamplePointsViewModel.Points.GroupBy(x => true)
                                    .Select(x => new
                    {
                        top    = x.Max(y => y.Latitude),
                        right  = x.Max(y => y.Longitude),
                        bottom = x.Min(y => y.Latitude),
                        left   = x.Min(y => y.Longitude),
                    })
                                    .Select(x => new Extent(x.top, x.left, x.right, x.bottom))
                                    .Single();

                    EventAggregator.GetEvent <ZoomToExtentEvent>().Publish(extent);

                    AppDataService.DisableDetectChanges();

                    Mapper.Map(SamplePointsViewModel, validationSession, opt =>
                    {
                        opt.Items[nameof(ValidationSession)] = validationSession;
                        opt.Items[nameof(LegendItem)]        = validationSession.LegendItems.ToDictionary(x => x.Id, x => x);
                    });

                    AppDataService.EnableDetectChanges();
                    await AppDataService.SaveChangesAsync();

                    // TODO: Localization
                    NotificationService.Notify("Points successfully synchronized!");
                });
            }
            else
            {
                Extent extent = SamplePointsViewModel.Points.GroupBy(x => true)
                                .Select(x => new
                {
                    top    = x.Max(y => y.Latitude),
                    right  = x.Max(y => y.Longitude),
                    bottom = x.Min(y => y.Latitude),
                    left   = x.Min(y => y.Longitude),
                })
                                .Select(x => new Extent(x.top, x.left, x.right, x.bottom))
                                .Single();

                EventAggregator.GetEvent <ZoomToExtentEvent>().Publish(extent);
            }

            MapClickCommand = new DelegateCommand(MapClickAsync);
        }
Exemplo n.º 8
0
        public static void ConfigureAppDataEntities(this IMapperConfigurationExpression mapperConfigurationExpression,
                                                    IContainerProvider containerProvider)
        {
            // Entities to view models
            mapperConfigurationExpression.CreateMap <ValidationSession, ViewModels.Main.ItemViewModel>()
            .ForMember(dest => dest.IsActive, opt => opt.Ignore())
            .ForMember(dest => dest.ItemTappedCommand, opt => opt.Ignore())
            .ForMember(dest => dest.IsChecked, opt => opt.Ignore())
            .ForMember(dest => dest.IsSelected, opt => opt.Ignore())
            .ForMember(dest => dest.ItemSelectedCommand, opt => opt.Ignore());

            mapperConfigurationExpression.CreateMap <ValidationSession, ViewModels.ValidationSessionOverview.ItemViewModel>()
            .ForMember(dest => dest.Pinned, opt => opt.Ignore())
            .ForMember(dest => dest.IsActive, opt => opt.Ignore())
            .ForMember(dest => dest.ItemTappedCommand, opt => opt.Ignore())
            .ForMember(dest => dest.IsSelected, opt => opt.Ignore())
            .ForMember(dest => dest.ItemSelectedCommand, opt => opt.Ignore());

            mapperConfigurationExpression.CreateMap <LegendItem, ItemViewModel>()
            .ForMember(dest => dest.Color, opt => opt.MapFrom(src => Color.FromArgb(src.Red, src.Green, src.Blue)))
            .ForMember(dest => dest.IsActive, opt => opt.Ignore())
            .ForMember(dest => dest.ItemTappedCommand, opt => opt.Ignore())
            .ForMember(dest => dest.IsSelected, opt => opt.Ignore())
            .ForMember(dest => dest.ItemSelectedCommand, opt => opt.Ignore())
            .EqualityComparison((source, dest) => dest.Id == source.Id);

            mapperConfigurationExpression.CreateMap <ValidationSession, SamplePointsViewModel>()
            .ForMember(dest => dest.Points, opt => opt.MapFrom(src => src.SampleItems));

            mapperConfigurationExpression.CreateMap <SampleItem, SamplePointViewModel>()
            .ForMember(dest => dest.Longitude, opt => opt.Ignore())
            .ForMember(dest => dest.Latitude, opt => opt.Ignore())
            .ForMember(dest => dest.Selected, opt => opt.Ignore())
            .ForMember(dest => dest.Radius, opt => opt.Ignore())
            .ForMember(dest => dest.FillColor, opt => opt.Ignore())
            .ForMember(dest => dest.StrokeColor, opt => opt.Ignore())
            .ForMember(dest => dest.StrokeWidth, opt => opt.Ignore())
            .ForMember(dest => dest.ValidationSessionId, opt => opt.Ignore())
            .ForMember(dest => dest.LegendItemId, opt => opt.Ignore())
            .AfterMap((src, dest) =>
            {
                Wkx.Point geometry = Geometry.Deserialize <WktSerializer>(src.Geometry) as Wkx.Point;

                if (geometry == null)
                {
                    throw new InvalidOperationException();
                }

                dest.Longitude = geometry.X.Value;
                dest.Latitude  = geometry.Y.Value;
            })
            .EqualityComparison((source, destination) => source.Id == destination.Id);

            mapperConfigurationExpression.CreateMap <LocalValidation, ViewModels.ValidationUpload.ItemViewModel>()
            .ForMember(dest => dest.LegendItemId, opt => opt.MapFrom(src => src.LegendItem == null ? null : (int?)src.LegendItem.Id))
            .ForMember(dest => dest.Uploaded, opt => opt.Ignore())
            .ForMember(dest => dest.IsActive, opt => opt.Ignore())
            .ForMember(dest => dest.ItemTappedCommand, opt => opt.Ignore())
            .ForMember(dest => dest.IsSelected, opt => opt.Ignore())
            .ForMember(dest => dest.ItemSelectedCommand, opt => opt.Ignore())
            .EqualityComparison((source, destination) => source.SampleItem.Id == destination.SampleItemId);

            // View models to entities
            mapperConfigurationExpression.CreateMap <ValidationSessionDetailViewModel, ValidationSession>()
            .ForMember(dest => dest.UserId, opt => opt.Ignore())
            .ForMember(dest => dest.User, opt => opt.Ignore())
            .ForMember(dest => dest.SampleItems, opt => opt.Ignore());

            mapperConfigurationExpression.CreateMap <ItemViewModel, LegendItem>()
            .ForMember(dest => dest.Red, opt => opt.MapFrom(src => src.Color.R * 255.0))
            .ForMember(dest => dest.Green, opt => opt.MapFrom(src => src.Color.G * 255.0))
            .ForMember(dest => dest.Blue, opt => opt.MapFrom(src => src.Color.B * 255.0))
            .ForMember(dest => dest.ValidationSession, opt => opt.Ignore())
            .ForMember(dest => dest.SampleItems, opt => opt.Ignore())
            .EqualityComparison((source, dest) => dest.Id == source.Id);

            mapperConfigurationExpression.CreateMap <SamplePointsViewModel, ValidationSession>(MemberList.Source)
            .ForMember(dest => dest.SampleItems, opt => opt.MapFrom(src => src.Points));

            mapperConfigurationExpression.CreateMap <SamplePointViewModel, SampleItem>()
            .ForMember(dest => dest.Geometry, configuration =>
            {
                configuration.ResolveUsing((source, destination) =>
                {
                    Wkx.Point point = new Wkx.Point(source.Longitude, source.Latitude);
                    return(point.SerializeString <WktSerializer>());
                });
            })
            .ForMember(dest => dest.ValidationSession, opt => opt.Ignore())
            .ForMember(dest => dest.LegendItem, opt => opt.Ignore())
            .ForMember(dest => dest.LocalValidation, opt => opt.Ignore())
            .AfterMap((src, dest, context) =>
            {
                ValidationSession validationSession       = (ValidationSession)context.Items[nameof(ValidationSession)];
                IDictionary <int, LegendItem> legendItems = (IDictionary <int, LegendItem>)context.Items[nameof(LegendItem)];

                dest.ValidationSession = validationSession;
                dest.LegendItem        = legendItems[src.LegendItemId];
            })
            .EqualityComparison((source, destination) => source.Id == destination.Id);

            mapperConfigurationExpression.CreateMap <ValidatePageViewModel, LocalValidation>()
            .ForMember(dest => dest.LegendItem, opt => opt.Ignore())
            .ForMember(dest => dest.SampleItem, opt => opt.Ignore())
            .ForMember(dest => dest.Uploaded, opt => opt.Ignore())
            .AfterMap(async(src, dest, context) =>
            {
                IAppDataService appDataService = containerProvider.Resolve <IAppDataService>();

                dest.SampleItem = await appDataService.GetSampleItemByIdAsync(src.SampleItemId, src.ValidationSessionId);
                dest.LegendItem = src.SelectedLegendItem != null
                                                ? await appDataService.GetLegendItemByIdAsync(src.SelectedLegendItem.Id, src.ValidationSessionId)
                                                : null;
            });
        }