public async Task RemoveSelectedSnapshots()
        {
            if (SelectedThumbnails.Count == 0)
            {
                await _dialogService.ShowAsync("Please select at least one snapshot.");

                return;
            }

            var response = await _dialogService.ShowConfirmationAsync("Do you really want to remove the selected snapshots?");

            if (response == ConfirmationAnswer.Cancel)
            {
                return;
            }

            IsBusy = true;
            var selectedThumbnails = SelectedThumbnails.ToList();

            foreach (var selThumb in selectedThumbnails)
            {
                var removedSnapshot = await _locationSnapshotDataService.RemoveSnapshotAsync(selThumb.Snapshot.Id);

                await _pictureService.RemoveSnapshotContentAsync(removedSnapshot);

                SnapshotThumbnails.Remove(SnapshotThumbnails.First(_ => _.Snapshot.Id == removedSnapshot.Id));
            }
            ;
            SetDefaultView();
            IsBusy = false;
        }
        public async void RemoveSelectedLocations_ShouldSucceed()
        {
            // Arrange
            SetUp();
            LocationsViewModel sit = null;
            var snapshotsToDelete  = new List <LocationSnapshot>
            {
                new LocationSnapshot {
                    Id = 1
                },
                new LocationSnapshot {
                    Id = 2
                }
            };

            _snapshotDataService.GetSnapshotsByLocationIdAsync(Arg.Any <int>())
            .Returns(_ =>
            {
                var tcs = new TaskCompletionSource <IEnumerable <LocationSnapshot> >();
                tcs.SetResult(snapshotsToDelete);
                return(tcs.Task);
            });
            _snapshotDataService.RemoveSnapshotAsync(Arg.Any <int>())
            .Returns(_ =>
            {
                var tcs = new TaskCompletionSource <LocationSnapshot>();
                tcs.SetResult(new LocationSnapshot());
                return(tcs.Task);
            });
            _pictureService.RemoveSnapshotContentAsync(Arg.Any <LocationSnapshot>())
            .Returns(_ => Task.CompletedTask);
            _locationDataService.RemoveLocationAsync(Arg.Any <int>())
            .Returns(_ =>
            {
                var tcs = new TaskCompletionSource <Location>();
                tcs.SetResult(sit.Locations[1]);
                return(tcs.Task);
            });

            // Act
            sit = CreateViewModel();
            await sit.OnLoaded();

            sit.SelectedLocations = new List <Location> {
                sit.Locations[1]
            };
            await sit.RemoveSelectedLocations();

            // Assert
            Assert.Equal(2, sit.Locations.Count);
            Assert.DoesNotContain(sit.Locations, _ => _.Name == "Prague");
            await _snapshotDataService.Received().RemoveSnapshotAsync(snapshotsToDelete[0].Id);

            await _snapshotDataService.Received().RemoveSnapshotAsync(snapshotsToDelete[1].Id);

            await _pictureService.Received().RemoveSnapshotContentAsync(snapshotsToDelete[0]);

            await _pictureService.Received().RemoveSnapshotContentAsync(snapshotsToDelete[1]);
        }
        public async void RemoveSelectedSnapshots_ShouldSucceed()
        {
            // Arrange
            SetUp();
            var navParams = new SnapshotsViewNavParams {
                SnapshotsIdsource = new Location()
            };
            var thumbnails = new List <SnapshotThumbnail>
            {
                new SnapshotThumbnail {
                    Snapshot = _snapshots[0]
                },
                new SnapshotThumbnail {
                    Snapshot = _snapshots[1]
                },
                new SnapshotThumbnail {
                    Snapshot = _snapshots[2]
                }
            };
            SnapshotsViewModel sit = null;

            _snapshotDataService.RemoveSnapshotAsync(Arg.Any <int>())
            .Returns(_ =>
            {
                var tcs = new TaskCompletionSource <LocationSnapshot>();
                tcs.SetResult(_snapshots[1]);
                return(tcs.Task);
            });
            _pictureService.RemoveSnapshotContentAsync(Arg.Any <LocationSnapshot>())
            .Returns(_ => Task.CompletedTask);

            // Act
            sit = CreateViewModel();
            sit.NavigationParam = navParams;
            await sit.OnLoaded();

            sit.BeginSelectSnapshot();
            sit.SelectedThumbnails = new List <SnapshotThumbnail> {
                thumbnails[1]
            };
            await sit.RemoveSelectedSnapshots();

            // Assert
            Assert.Equal(2, sit.SnapshotThumbnails.Count);
            Assert.DoesNotContain(sit.SnapshotThumbnails.Select(_ => _.Snapshot), _ => _.PictureFileName == "Barcelona_2.jpg");
            await _snapshotDataService.Received().RemoveSnapshotAsync(_snapshots[1].Id);

            await _pictureService.Received().RemoveSnapshotContentAsync(_snapshots[1]);
        }
Esempio n. 4
0
        public async Task <IActionResult> DeleteSnapshot(int id)
        {
            var changeTargets = await _locationSnapshotDataService.GetSnapshotsByIdsAsync(new[] { id });

            if (changeTargets.Count() != 1)
            {
                _logger.LogWarning("Location snapshot not found. Location snapshot ID = {0}", id);
                return(NotFound());
            }

            var deletedSnapshot = await _locationSnapshotDataService.RemoveSnapshotAsync(id);

            var result = Mapper.Map <LocationSnapshot, LocationSnapshotDto>(deletedSnapshot);

            return(Ok(result));
        }
Esempio n. 5
0
        public async Task RemoveSelectedLocations()
        {
            if (SelectedLocations.Count == 0)
            {
                await _dialogService.ShowAsync("Please select at least one location.");

                return;
            }

            var response = await _dialogService.ShowConfirmationAsync("Do you really want to remove the selected locations?");

            if (response == ConfirmationAnswer.Cancel)
            {
                return;
            }

            IsBusy = true;
            var selectedLocations = SelectedLocations.ToList();

            foreach (var selLoc in selectedLocations)
            {
                var snapshots = await _locationSnapshotDataService.GetSnapshotsByLocationIdAsync(selLoc.Id);

                var deletionTasks = snapshots.Select(async _ =>
                {
                    await _locationSnapshotDataService.RemoveSnapshotAsync(_.Id);
                    await _pictureService.RemoveSnapshotContentAsync(_);
                });
                await Task.WhenAll(deletionTasks);

                var removedLocation = await _locationDataService.RemoveLocationAsync(selLoc.Id);

                Locations.Remove(Locations.First(_ => _.Id == removedLocation.Id));
            }
            ;
            SetDefaultView();
            IsBusy = false;
        }