Пример #1
0
        public async Task <ActionResult <MapLayerResponse> > PostCreateMapLayerAsync(
            [FromServices] NaheulbookExecutionContext executionContext,
            [FromRoute] int mapId,
            [FromBody] MapLayerRequest request
            )
        {
            var map = await _mapService.CreateMapLayerAsync(executionContext, mapId, request);

            return(_mapper.Map <MapLayerResponse>(map));
        }
Пример #2
0
        public async Task <MapLayer> EditMapLayerAsync(NaheulbookExecutionContext executionContext, int mapLayerId, MapLayerRequest request)
        {
            using (var uow = _unitOfWorkFactory.CreateUnitOfWork())
            {
                var mapLayer = await uow.MapLayers.GetAsync(mapLayerId);

                if (mapLayer == null)
                {
                    throw new MapLayerNotFoundException(mapLayerId);
                }

                switch (mapLayer.Source)
                {
                case "official":
                    await _authorizationUtil.EnsureAdminAccessAsync(executionContext);

                    break;

                case "private":
                    break;

                default:
                    throw new InvalidSourceException(request.Source);
                }

                switch (request.Source)
                {
                case "official":
                    await _authorizationUtil.EnsureAdminAccessAsync(executionContext);

                    break;

                case "private":
                    break;

                default:
                    throw new InvalidSourceException(request.Source);
                }

                mapLayer.Name   = request.Name;
                mapLayer.Source = request.Source;
                mapLayer.IsGm   = request.IsGm;
                mapLayer.UserId = request.Source == "official" ? (int?)null : executionContext.UserId;

                await uow.SaveChangesAsync();

                await uow.MapLayers.LoadMarkersForResponseAsync(mapLayer);

                return(mapLayer);
            }
        }
Пример #3
0
        public async Task <MapLayer> CreateMapLayerAsync(NaheulbookExecutionContext executionContext, int mapId, MapLayerRequest request)
        {
            using (var uow = _unitOfWorkFactory.CreateUnitOfWork())
            {
                switch (request.Source)
                {
                case "official":
                    await _authorizationUtil.EnsureAdminAccessAsync(executionContext);

                    break;

                case "private":
                    break;

                default:
                    throw new InvalidSourceException(request.Source);
                }

                var map = await uow.Maps.GetAsync(mapId);

                if (map == null)
                {
                    throw new MapNotFoundException(mapId);
                }

                var mapLayer = new MapLayer
                {
                    Name   = request.Name,
                    Source = request.Source,
                    IsGm   = request.IsGm,
                    MapId  = mapId,
                    UserId = request.Source == "official" ? (int?)null : executionContext.UserId
                };

                uow.MapLayers.Add(mapLayer);
                await uow.SaveChangesAsync();

                return(mapLayer);
            }
        }