Esempio n. 1
0
        public IActionResult Csv()
        {
            Task.Run(() =>
            {
                var Filess         = Request.Form.Files;
                var file           = Request.Form.Files[0];
                string folderName  = "Upload";
                string webRootPath = _hostingEnvironment.WebRootPath;
                string newPath     = Path.Combine(webRootPath, folderName);
                string fullPath    = "";
                if (!Directory.Exists(newPath))
                {
                    Directory.CreateDirectory(newPath);
                }

                if (file.Length > 0)
                {
                    string fileName = Microsoft.Net.Http.Headers.ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.ToString().Trim('"');
                    fullPath        = Path.Combine(newPath, fileName);
                    using (var stream = new FileStream(fullPath, FileMode.Create))
                    {
                        file.CopyTo(stream);
                    }
                    var customerId = Convert.ToInt32(Path.GetFileNameWithoutExtension(fullPath));
                    _csvReaderService.ProcessCsv(fullPath, customerId);
                }
            });

            return(Accepted());
        }