Esempio n. 1
0
        public async Task <Persil> Upload([FromForm] EditPersilViewModel model)
        {
            var persil = await dbContext.Set <Persil>().FirstOrDefaultAsync(p => p.Id == model.PersilId);

            if (persil == null)
            {
                throw new NotFoundException();
            }

            dbContext.Entry(persil).State = EntityState.Modified;

            persil.Status       = model.PersilStatus;
            persil.TotalSize    = model.PersilTotalSize;
            persil.TotalSubject = model.PersilTotalSubject;
            persil.DateModified = DateTime.Now;

            if (model.File != null)
            {
                var features = TopologyHelper.GetFeatureCollectionWgs84(model.File);
                persil.Geojson = TopologyHelper.GetGeojson(features);

                // Copy map file to disk
                var persilDirectoryPath = Path.Combine(_hostingEnvironment.WebRootPath, "persil");
                var regionDirectoryPath = Path.Combine(persilDirectoryPath, persil.FkRegionId);
                var destinationFilePath = Path.Combine(regionDirectoryPath, persil.Id + ".zip");
                await IOHelper.StreamCopyAsync(destinationFilePath, model.File);
            }

            await dbContext.SaveChangesAsync();

            return(persil);
        }
Esempio n. 2
0
        public async Task<ToraMap> Upload([FromForm]UploadToraMapViewModel model)
        {
            var toraObject = await dbContext.Set<ToraObject>().FirstOrDefaultAsync(to => to.Id == model.ToraObjectId);
            if (toraObject == null)
                throw new NotFoundException();

            var toraMap = await dbContext.Set<ToraMap>().FirstOrDefaultAsync(tm => tm.FkToraObjectId == toraObject.Id);

            if (toraMap == null)
            {
                toraMap = new ToraMap { FkToraObjectId = toraObject.Id };
                dbContext.Entry(toraMap).State = EntityState.Added;
            }
            else
            {
                dbContext.Entry(toraMap).State = EntityState.Modified;
            }

            toraMap.FkRegionId = toraObject.FkRegionId;
            toraMap.Name = toraObject.Name;

            var features = TopologyHelper.GetFeatureCollectionWgs84(model.File);
            toraMap.Geojson = TopologyHelper.GetGeojson(features);
            toraMap.Size = TopologyHelper.GetArea(features);

            await dbContext.SaveChangesAsync();

            // Copy map file to disk
            var toraMapDirectoryPath = Path.Combine(_hostingEnvironment.WebRootPath, "tora", "map");
            var regionDirectoryPath = Path.Combine(toraMapDirectoryPath, toraObject.FkRegionId);
            var destinationFilePath = Path.Combine(regionDirectoryPath, toraMap.Id + ".zip");
            await IOHelper.StreamCopyAsync(destinationFilePath, model.File);

            return toraMap;
        }
        public async Task <VillageBorderMap> Upload([FromForm] UploadVillageBorderMapViewModel model)
        {
            var region = await dbContext.Set <Region>().FirstOrDefaultAsync(r => r.Id == model.RegionId);

            if (region == null)
            {
                throw new NotFoundException();
            }

            var villageBorderMap = await dbContext.Set <VillageBorderMap>().FirstOrDefaultAsync(vbm => vbm.FkRegionId == model.RegionId);

            if (villageBorderMap == null)
            {
                villageBorderMap = new VillageBorderMap {
                    FkRegionId = model.RegionId
                };
                dbContext.Entry(villageBorderMap).State = EntityState.Added;
            }
            else
            {
                dbContext.Entry(villageBorderMap).State = EntityState.Modified;
            }

            villageBorderMap.Name = region.Name;

            var features = TopologyHelper.GetFeatureCollectionWgs84(model.File);

            villageBorderMap.Geojson = TopologyHelper.GetGeojson(features);
            villageBorderMap.Size    = TopologyHelper.GetArea(features);

            await dbContext.SaveChangesAsync();

            // Copy map file to disk
            var villageBorderMapDirectoryPath = Path.Combine(_hostingEnvironment.WebRootPath, "villagebordermap");
            var regionDirectoryPath           = Path.Combine(villageBorderMapDirectoryPath, region.Id);
            var destinationFilePath           = Path.Combine(regionDirectoryPath, villageBorderMap.Id + ".zip");
            await IOHelper.StreamCopyAsync(destinationFilePath, model.File);

            return(villageBorderMap);
        }
Esempio n. 4
0
        public async Task <BaseLayer> Upload([FromForm] UploadBaseLayerViewModel model)
        {
            BaseLayer baseLayer = null;

            if (model.Id > 0)
            {
                baseLayer = await dbContext.Set <BaseLayer>().FirstOrDefaultAsync(o => o.Id == model.Id);
            }

            if (baseLayer == null)
            {
                baseLayer = new BaseLayer();
                dbContext.Entry(baseLayer).State = EntityState.Added;
            }
            else
            {
                dbContext.Entry(baseLayer).State = EntityState.Modified;
            }

            baseLayer.Label = model.Label;
            baseLayer.Color = model.Color;

            if (baseLayer.Id <= 0 || model.File != null)
            {
                var features = TopologyHelper.GetFeatureCollectionWgs84(model.File);
                baseLayer.Geojson = TopologyHelper.GetGeojson(features);
                await dbContext.SaveChangesAsync();

                var baseLayerDirectoryPath = Path.Combine(_hostingEnvironment.WebRootPath, "baseLayer");
                var destinationFilePath    = Path.Combine(baseLayerDirectoryPath, baseLayer.Id + ".zip");
                await IOHelper.StreamCopyAsync(destinationFilePath, model.File);
            }
            else
            {
                await dbContext.SaveChangesAsync();
            }

            return(baseLayer);
        }