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)); }
public async Task <IActionResult> ImportPOIs() { var model = new ImportPOIsView(); return(View(model)); }
public IActionResult ImportPOIs() { var model = new ImportPOIsView(); return(View(model)); }