protected override async Task ExecutePrimaryActionAsync() { await base.ExecutePrimaryActionAsync(); foreach (ItemViewModel item in Items) { try { await ApiClient.PostValidationAsync(ValidationSessionId, item.SampleItemId, Mapper.Map <ValidationCreateModel>(item)); item.Uploaded = true; LocalValidation localValidation = await AppDataService.GetLocalValidationByIdAsync(item.SampleItemId, ValidationSessionId); localValidation.Uploaded = true; } catch (Exception e) { // TODO: Notify user } } await AppDataService.SaveChangesAsync(); }
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); }