示例#1
0
        public async Task <IActionResult> Export(string data)
        {
            int[] idsToExport = null;
            try
            {
                idsToExport = Array.ConvertAll(data.Split(","), id => int.Parse(id));
            }
            catch (NullReferenceException ex)
            {
                //TODO log ex
                return(StatusCode(500, "data parameter cannot be empty"));
            }
            catch (FormatException ex)
            {
                //TODO log ex
                return(StatusCode(500, "data parameter should be numeric polygons ids seprated  by comma"));
            }

            ConcurrentBag <FileEntity> fileList = new ConcurrentBag <FileEntity>();

            var polygonsRows = await _polymapService.ListPolygonsByIds(idsToExport);

            var apiKey = _config.GetSection("AppSettings").GetSection("MapApiKey").Value;

            Parallel.ForEach(polygonsRows, polygon =>
            {
                fileList.Add(_polymapService.GetPdfFileForPolygon(PolygonUtilities.GetMapUrl(polygon.LocationCoordinates, apiKey), polygon.Id));
            });

            var response = PrepareFileContentRersult(fileList);

            if (response != null)
            {
                return(response);
            }

            return(StatusCode(404, "All polygon ids provided is not exists."));
        }