Пример #1
0
        public async Task <List <ColumnControl> > FindByCompany(string company)
        {
            var control = await _columnControlRepository.FindByCompany(company);

            return(control);
        }
        public async Task <List <dynamic> > ReadFile(string filename, string subject)
        {
            string        company     = "";
            List <string> entityIndex = new List <string>();

            if (subject.ToUpper().Contains("SULAMERICA"))
            {
                company = "Sulamerica";
            }
            else if (subject.ToUpper().Contains("UNIMED"))
            {
                company = "Unimed";
            }

            List <ColumnControl> control = await _columnControlRepository.FindByCompany(company);

            string[] lines = File.ReadAllLines(Directory.GetCurrentDirectory() + filename);

            Process process = await _processRepository.CreateProcess(company);

            string field = "";

            foreach (string line in lines)
            {
                foreach (ColumnControl item in control)
                {
                    for (int i = item.Start; i <= item.End; i++)
                    {
                        if (field.Length != item.Size)
                        {
                            field += line[i];
                        }
                        else
                        {
                            break;
                        }
                    }
                    entityIndex.Add(field);
                    field = "";
                }

                if (subject.ToUpper().Contains("SULAMERICA"))
                {
                    Sulamerica obj = new Sulamerica
                    {
                        Sequencia       = entityIndex[0],
                        Carteirinha     = entityIndex[1],
                        Nome            = entityIndex[2],
                        CPF             = entityIndex[3],
                        DataRegistro    = entityIndex[4],
                        Mais            = entityIndex[5],
                        Valor           = InsertDot(entityIndex[6]),
                        CodigoAleatorio = entityIndex[7],
                        Nascimento      = entityIndex[8],
                        CNPJ            = entityIndex[9],
                        NomeColaborador = entityIndex[10],
                        NE      = entityIndex[11],
                        Process = process
                    };

                    list.Add(obj);

                    await _sulamericaRepository.Create(obj);

                    entityIndex.Clear();
                }
                else if (subject.ToUpper().Contains("UNIMED"))
                {
                    Unimed obj = new Unimed
                    {
                        TipoServico              = entityIndex[0],
                        DataConsumo              = DateTime.ParseExact(entityIndex[1], "ddMMyyyy", CultureInfo.CreateSpecificCulture("pt-BR")),
                        ne                       = entityIndex[2],
                        CodigoDependenteSistema  = entityIndex[3],
                        Nome                     = entityIndex[4],
                        Crm                      = entityIndex[5],
                        ValorDespesa             = decimal.Parse(entityIndex[6]),
                        Amb                      = entityIndex[7],
                        ControleUnimedLotacao    = entityIndex[8],
                        ControleUnimedAcomodacao = entityIndex[9],
                        Pago                     = entityIndex[10],
                        Process                  = process
                    };

                    list.Add(obj);

                    await _unimedRepository.Create(obj);

                    entityIndex.Clear();
                }
            }

            return(list);
        }