Beispiel #1
0
        public async Task <MapMarkerLink> CreateMapMarkerLinkAsync(
            NaheulbookExecutionContext executionContext,
            int mapMarkerId,
            MapMarkerLinkRequest request
            )
        {
            using var uow = _unitOfWorkFactory.CreateUnitOfWork();

            var mapMarker = await uow.MapMarkers.GetWithLayerAsync(mapMarkerId);

            if (mapMarker == null)
            {
                throw new MapMarkerNotFoundException(mapMarkerId);
            }

            await _authorizationUtil.EnsureCanEditMapLayerAsync(executionContext, mapMarker.Layer);

            var targetMap = await uow.Maps.GetAsync(request.TargetMapId);

            if (targetMap == null)
            {
                throw new MapNotFoundException(request.TargetMapId);
            }

            if (request.TargetMapMarkerId.HasValue)
            {
                var targetMapMarker = await uow.MapMarkers.GetWithLayerAsync(request.TargetMapMarkerId.Value);

                if (targetMapMarker == null)
                {
                    throw new MapMarkerNotFoundException(request.TargetMapMarkerId.Value);
                }

                await _authorizationUtil.EnsureCanEditMapLayerAsync(executionContext, targetMapMarker.Layer);
            }

            var mapMarkerLink = new MapMarkerLink
            {
                Name              = request.Name,
                MapMarkerId       = mapMarkerId,
                TargetMap         = targetMap,
                TargetMapId       = request.TargetMapId,
                TargetMapMarkerId = request.TargetMapMarkerId
            };

            uow.MapMarkerLinks.Add(mapMarkerLink);

            await uow.SaveChangesAsync();

            return(mapMarkerLink);
        }
        public async Task <ActionResult <MapMarkerLinkResponse> > CreateMapMarkerLinkAsync(
            [FromServices] NaheulbookExecutionContext naheulbookExecutionContext,
            [FromRoute] int mapMarkerId,
            [FromBody] MapMarkerLinkRequest request
            )
        {
            try
            {
                var marker = await _mapService.CreateMapMarkerLinkAsync(naheulbookExecutionContext, mapMarkerId, request);

                return(_mapper.Map <MapMarkerLinkResponse>(marker));
            }
            catch (MapMarkerNotFoundException ex)
            {
                throw new HttpErrorException(StatusCodes.Status404NotFound, ex);
            }
        }
Beispiel #3
0
        public async Task <MapMarkerLink> EditMapMarkerLinkAsync(NaheulbookExecutionContext executionContext, int mapMarkerLinkId, MapMarkerLinkRequest request)
        {
            using var uow = _unitOfWorkFactory.CreateUnitOfWork();

            var mapMarkerLink = await uow.MapMarkerLinks.GetWithLayerAsync(mapMarkerLinkId);

            if (mapMarkerLink == null)
            {
                throw new MapMarkerNotFoundException(mapMarkerLinkId);
            }

            await _authorizationUtil.EnsureCanEditMapLayerAsync(executionContext, mapMarkerLink.MapMarker.Layer);

            mapMarkerLink.Name              = request.Name;
            mapMarkerLink.TargetMapId       = request.TargetMapId;
            mapMarkerLink.TargetMapMarkerId = request.TargetMapMarkerId;

            await uow.SaveChangesAsync();

            await uow.MapMarkerLinks.LoadTargetMapAsync(mapMarkerLink);

            return(mapMarkerLink);
        }