예제 #1
0
 private void AtualizarArquivoUpload(ArquivoUploadEntidade rowArquivoUpload)
 {
     if (rowArquivoUpload.IND_STATUS == DMN_STATUS_EFD_UPLOAD.NAO_PROCESSADO)
     {
         rowArquivoUpload.IND_STATUS = DMN_STATUS_EFD_UPLOAD.PROCESSADO;
         _proxyArquivoUpload.Atualizar(rowArquivoUpload);
     }
 }
예제 #2
0
        public IActionResult UploadFile(IFormFile file, decimal oidUsuarioContribuinte)
        {
            try
            {
                string folderName  = "Upload";
                string webRootPath = HostingEnvironment.ContentRootPath;
                string newPath     = Path.Combine(webRootPath, folderName);

                if (!Directory.Exists(newPath))
                {
                    Directory.CreateDirectory(newPath);
                }

                long oidArquivoUpload = 0;

                if (file.Length > 0)
                {
                    string fileName      = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');
                    var    filePathArray = fileName.Split(".");
                    var    ext           = filePathArray[filePathArray.Length - 1];

                    if (ext.ToLower() != "csv")
                    {
                        throw new Exception("Formato de arquivo inválido. Apenas arquivos .csv são suportados.");
                    }

                    string fullPath = Path.Combine(newPath, fileName);
                    using (var stream = new FileStream(fullPath, FileMode.Create))
                    {
                        file.CopyTo(stream);
                    }

                    var arquivo = new ArquivoUploadEntidade
                    {
                        OID_USUARIO_CONTRIBUINTE = oidUsuarioContribuinte,
                        DTA_UPLOAD           = DateTime.Now,
                        IND_STATUS           = DMN_STATUS_EFD_UPLOAD.NAO_PROCESSADO,
                        NOM_ARQUIVO_LOCAL    = string.Format(@"Upload\{0}", fileName),
                        NOM_ARQUIVO_ORIGINAL = fileName,
                        NOM_DIRETORIO_LOCAL  = "Upload",
                        NOM_EXT_ARQUIVO      = ext
                    };

                    oidArquivoUpload = new ArquivoUploadProxy().Inserir(arquivo);
                }

                return(Json(oidArquivoUpload));
            }
            catch (System.Exception ex)
            {
                return(Json("Upload Failed: " + ex.Message));
            }
        }