Exemplo n.º 1
0
        public async Task <IActionResult> ImportPOIs(ImportPOIsView modal, IFormFile fileToUpload, CancellationToken cancellationToken)
        {
            if (fileToUpload != null && fileToUpload.Length > 0)
            {
                //Path.GetExtension(file.FileName).ToLower() == "kmz"

                //var extenion = file.FileName.Substring(file.FileName.IndexOf(char.Parse(".")) + 1, file.FileName.Length - file.FileName.IndexOf(char.Parse(".")) - 1);
                var extenion = Path.GetExtension(fileToUpload.FileName).ToLower();

                if (!String.IsNullOrWhiteSpace(extenion))
                {
                    extenion = extenion.ToLower();
                }

                if (extenion != ".kml" && extenion != ".kmz")
                {
                    ModelState.AddModelError("fileToUpload", string.Format("File type ({0}) is not a KMZ or KML extension to import POIs.", extenion));
                }

                if (fileToUpload.Length > 10000000)
                {
                    ModelState.AddModelError("fileToUpload", "Document is too large, must be smaller then 10MB.");
                }
            }

            if (ModelState.IsValid)
            {
                var coordinates = _kmlProvider.ImportFile(fileToUpload.OpenReadStream(), Path.GetExtension(fileToUpload.FileName).ToLower() == ".kmz");

                foreach (var coordinate in coordinates)
                {
                    var poi = new Poi();
                    poi.PoiTypeId = modal.TypeId;

                    if (coordinate.Latitude.HasValue && coordinate.Longitude.HasValue)
                    {
                        poi.Latitude  = coordinate.Latitude.Value;
                        poi.Longitude = coordinate.Longitude.Value;

                        await _mappingService.SavePOIAsync(poi, cancellationToken);
                    }
                }

                return(RedirectToAction("POIs"));
            }

            return(View(modal));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> ImportPOIs()
        {
            var model = new ImportPOIsView();

            return(View(model));
        }
Exemplo n.º 3
0
        public IActionResult ImportPOIs()
        {
            var model = new ImportPOIsView();

            return(View(model));
        }