public void inserir(CT2Model c)
        {
            //Validações regra de negócio
            c.validate();

            OracleCommand command = this.con.CreateCommand();

            if (usaTransacao)
                command.Transaction = this._transaction;

            //command.CommandText = this.CriaStringInsert();
            command.CommandText = "P_AMC_PERSONNEL_INTEGRATION";
            command.CommandType = CommandType.StoredProcedure;

            //Cria parametros
            OracleParameter DATA = new OracleParameter();
            DATA.Value = c.Data;
            DATA.ParameterName = "DATA";

            OracleParameter LOTE = new OracleParameter();
            LOTE.Value = c.Lote;
            LOTE.ParameterName = "LOTE";

            OracleParameter SUBLOTE = new OracleParameter();
            SUBLOTE.Value = c.SubLote;
            SUBLOTE.ParameterName = "SUBLOTE";

            OracleParameter DOC = new OracleParameter();
            DOC.Value = c.Doc;
            DOC.ParameterName = "DOC";

            OracleParameter LINHA = new OracleParameter();
            LINHA.Value = c.Linha;
            LINHA.ParameterName = "LINHA";

            OracleParameter MOEDA = new OracleParameter();
            MOEDA.Value = c.Moeda;
            MOEDA.ParameterName = "MOEDA";

            OracleParameter DC = new OracleParameter();
            DC.Value = c.DC;
            DC.ParameterName = "DC";

            OracleParameter CTADEB = new OracleParameter();
            CTADEB.DbType = DbType.String;
            CTADEB.Value = c.CTADEB.Substring(11, 9);
            CTADEB.ParameterName = "CTADEB";

            OracleParameter CTACRED = new OracleParameter();
            CTACRED.Value = c.CTACRED.Substring(11, 9);
            CTACRED.ParameterName = "CTACRED";

            OracleParameter VALOR = new OracleParameter();
            VALOR.DbType = DbType.Decimal;
            VALOR.Value = c.Valor;
            VALOR.ParameterName = "VALOR";

            OracleParameter HISTORICO = new OracleParameter();
            HISTORICO.Value = c.Historico;
            HISTORICO.ParameterName = "HISTORICO";

            OracleParameter CCD = new OracleParameter();
            CCD.Value = c.CCD;
            CCD.ParameterName = "CCD";

            OracleParameter CCC = new OracleParameter();
            CCC.Value = c.CCC;
            CCC.ParameterName = "CCC";

            OracleParameter EMPORI = new OracleParameter();
            EMPORI.Value = c.Empori;
            EMPORI.ParameterName = "EMPORI";

            OracleParameter FILORI = new OracleParameter();
            FILORI.Value = c.Filori;
            FILORI.ParameterName = "FILORI";

            OracleParameter TPSALD = new OracleParameter();
            TPSALD.Value = c.TPSald;
            TPSALD.ParameterName = "TPSALD";

            OracleParameter SEQ = new OracleParameter();
            SEQ.Value = c.SEQ;
            SEQ.ParameterName = "SEQ";

            OracleParameter MANUAL = new OracleParameter();
            MANUAL.Value = c.Manual;
            MANUAL.ParameterName = "MANUAL";

            OracleParameter ORIGEM = new OracleParameter();
            ORIGEM.Value = c.Origem;
            ORIGEM.ParameterName = "ORIGEM";

            OracleParameter ROTINA = new OracleParameter();
            ROTINA.Value = c.Rotina;
            ROTINA.ParameterName = "ROTINA";

            OracleParameter AGLUTINA = new OracleParameter();
            AGLUTINA.Value = c.Aglutina;
            AGLUTINA.ParameterName = "AGLUTINA";

            OracleParameter LP = new OracleParameter();
            LP.Value = c.LP;
            LP.ParameterName = "LP";

            OracleParameter SEQHIST = new OracleParameter();
            SEQHIST.Value = c.SEQHIST;
            SEQHIST.ParameterName = "SEQHIST";

            OracleParameter SEQLAN = new OracleParameter();
            SEQLAN.Value = c.SEQLAN;
            SEQLAN.ParameterName = "SEQLAN";

            OracleParameter CRCONV = new OracleParameter();
            CRCONV.Value = c.CRCONV;
            CRCONV.ParameterName = "CRCONV";

            OracleParameter DATAV = new OracleParameter();
            DATAV.Value = c.DATAV;
            DATAV.ParameterName = "DATAV";

            OracleParameter MLTSALD = new OracleParameter();
            MLTSALD.Value = c.MLTSALD;
            MLTSALD.ParameterName = "MLTSALD";

            OracleParameter CTLSALD = new OracleParameter();
            CTLSALD.Value = c.CTLSALD;
            CTLSALD.ParameterName = "CTLSALD";

            OracleParameter USERGI = new OracleParameter();
            USERGI.Value = c.USERGI;
            USERGI.ParameterName = "USERGI";

            OracleParameter MSFIL = new OracleParameter();
            MSFIL.Value = c.MSFIL;
            MSFIL.ParameterName = "MSFIL";

            command.Parameters.Add(DATA);
            command.Parameters.Add(LOTE);
            command.Parameters.Add(SUBLOTE);
            command.Parameters.Add(DOC);
            command.Parameters.Add(LINHA);
            command.Parameters.Add(MOEDA);
            command.Parameters.Add(DC);
            command.Parameters.Add(CTADEB);
            command.Parameters.Add(CTACRED);
            command.Parameters.Add(VALOR);
            command.Parameters.Add(HISTORICO);
            command.Parameters.Add(CCD);
            command.Parameters.Add(CCC);
            command.Parameters.Add(EMPORI);
            command.Parameters.Add(FILORI);
            command.Parameters.Add(TPSALD);
            command.Parameters.Add(SEQ);
            command.Parameters.Add(MANUAL);
            command.Parameters.Add(ORIGEM);
            command.Parameters.Add(ROTINA);
            command.Parameters.Add(AGLUTINA);
            command.Parameters.Add(LP);
            command.Parameters.Add(SEQHIST);
            command.Parameters.Add(SEQLAN);
            command.Parameters.Add(CRCONV);
            command.Parameters.Add(DATAV);
            command.Parameters.Add(MLTSALD);
            command.Parameters.Add(CTLSALD);
            command.Parameters.Add(USERGI);
            command.Parameters.Add(MSFIL);

            try
            {
                command.ExecuteNonQuery();
            }
            catch (OracleException ex)
            {
                if (usaTransacao)
                    this._transaction.Rollback();

                con.Close();
                throw ex;
            }
        }
        public async Task<JsonResult> Upload()
        {
            try
            {
                CT2Repository _repository = new CT2Repository();
                //MigrationRepository _mRepository = new MigrationRepository();
                foreach (string file in Request.Files)
                {
                    var fileContent = Request.Files[file];
                    if (fileContent != null && fileContent.ContentLength > 0)
                    {
                        var stream = fileContent.InputStream;
                        var fileName = GetTimestamp(DateTime.Now);
                        var path = Path.Combine(Server.MapPath("~/App_Data/Files"), fileName);
                        fileContent.SaveAs(path);

                        //ler o arquivo
                        string[] lines = System.IO.File.ReadAllLines(path);
                        

                        foreach (string line in lines)
                        {
                            CT2Model c = new CT2Model();
                            //Preenche o objeto
                            c.Data = line.Substring(0, 8);
                            c.Lote = line.Substring(8, 6);
                            c.SubLote = line.Substring(14, 3);
                            c.Doc = line.Substring(17, 6);
                            c.Linha = line.Substring(23, 3);
                            c.Moeda = line.Substring(26, 2);
                            c.DC = line.Substring(28, 1);
                            c.CTADEB = line.Substring(29, 20);
                            c.CTACRED = line.Substring(49, 20);
                            c.Valor = Convert.ToDecimal(line.Substring(69, 16));
                            c.Historico = line.Substring(85, 40);
                            c.CCD = line.Substring(125, 9);
                            c.CCC = line.Substring(134, 9);
                            c.Empori = line.Substring(143, 2);
                            c.Filori = line.Substring(145, 2);
                            c.TPSald = line.Substring(147, 1);
                            c.SEQ = line.Substring(148, 10);
                            c.Manual = line.Substring(158, 1);
                            c.Origem = line.Substring(159, 100);
                            c.Rotina = line.Substring(259, 10);
                            c.Aglutina = line.Substring(269, 1);
                            c.LP = line.Substring(270, 3);
                            c.SEQHIST = line.Substring(273, 3);
                            c.SEQLAN = line.Substring(276, 3);
                            c.CRCONV = line.Substring(279, 1);
                            c.DATAV = line.Substring(280, 8);
                            c.MLTSALD = line.Substring(288, 20);
                            c.CTLSALD = line.Substring(308, 1);
                            c.USERGI = line.Substring(309, 17);
                            c.MSFIL = line.Substring(326, 2);

                            //Salva no banco(OBS -> UTILIZA TRANSAÇÃO!)
                            _repository.inserir(c);
                        }

                        /*MigrationModel m = new MigrationModel();
                        m.status = "Migrado";
                        m.Description = "Migração realizada em: " + GetTimestamp(DateTime.Now);
                        m.FileId = fileName;
                        _mRepository.salva(m);*/

                    }
                }
                _repository.commit(); // Efetua o commit no banco de dados;
            }
            catch (Exception ex)
            {
               // Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return Json("Erro no processamento: " + ex.Message);
            }

            return Json("Arquivo processado com sucesso.");
        }