Example #1
0
        public async Task <IActionResult> UpdateSnapshot(int id, [FromBody] LocationSnapshotForUpdateDto snapshotForUpdate)
        {
            if (id != snapshotForUpdate.Id)
            {
                _logger.LogWarning("Bad request. Location snapshot ID mismatch: {0} != {Id}", id, snapshotForUpdate.Id);
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                _logger.LogWarning("Bad request. Model state invalid: {@ModelState}", ModelState);
                return(BadRequest(ModelState));
            }

            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 snapshotToUpdate = Mapper.Map <LocationSnapshotForUpdateDto, LocationSnapshot>(snapshotForUpdate);
            var updatedSnapshot  = await _locationSnapshotDataService.UpdateSnapshotAsync(snapshotToUpdate);

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

            return(Ok(result));
        }
Example #2
0
        public async Task OnCaptureSnapshot()
        {
            IsBusy = true;
            var pictureData = await _cameraService.CapturePhotoWithOrientationAsync();

            var now              = DateTime.Now.ToString("yyyyMMdd_HH_mm_ss");
            var pictureFileName  = $"LocationCapture_{now}.jpg";
            var locationSnapshot = new LocationSnapshot
            {
                LocationId      = GetLocationId(),
                PictureFileName = pictureFileName,
                Longitude       = double.MinValue,
                Latitude        = double.MinValue,
                Altitude        = double.MinValue,
                DateCreated     = DateTime.Now
            };

            var newSnapshot = await _locationSnapshotDataService.AddSnapshotAsync(locationSnapshot);

            await _pictureService.SaveSnapshotContentAsync(newSnapshot, pictureData);

            IsBusy = false;

            var locationDescriptor = await _locationService.GetCurrentLocationAsync();

            if (!(await _locationSnapshotDataService.GetSnapshotsByIdsAsync(new[] { newSnapshot.Id })).Any())
            {
                return;
            }
            newSnapshot.Longitude = locationDescriptor.Longitude;
            newSnapshot.Latitude  = locationDescriptor.Latitude;
            newSnapshot.Altitude  = locationDescriptor.Altitude;
            await _locationSnapshotDataService.UpdateSnapshotAsync(newSnapshot);

            _eventAggregator.GetEvent <GeolocationReadyEvent>().Publish(locationDescriptor);
        }