public async Task <IActionResult> PutAdquirente(int id, Adquirente adquirente)
        {
            if (id != adquirente.Id)
            {
                return(BadRequest());
            }

            _context.Entry(adquirente).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AdquirenteExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Esempio n. 2
0
        public List <Adquirente> GetMBR()
        {
            var Adquirentes = new List <Adquirente>();

            Adquirente adq = new Adquirente();

            adq.Nome = "Adquirente A";
            adq.Taxas.Add(new Taxas("Visa", 2.25, 2.00));
            adq.Taxas.Add(new Taxas("Master", 2.35, 1.98));

            Adquirentes.Add(adq);

            adq = new Adquirente();

            adq.Nome = "Adquirente B";
            adq.Taxas.Add(new Taxas("Visa", 2.50, 2.08));
            adq.Taxas.Add(new Taxas("Master", 2.65, 1.75));

            Adquirentes.Add(adq);

            adq = new Adquirente();

            adq.Nome = "Adquirente C";
            adq.Taxas.Add(new Taxas("Visa", 2.75, 2.16));
            adq.Taxas.Add(new Taxas("Master", 3.10, 1.58));

            Adquirentes.Add(adq);

            return(Adquirentes);
        }
        public async Task <ActionResult <Adquirente> > PostAdquirente(Adquirente adquirente)
        {
            _context.Adquirente.Add(adquirente);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetAdquirente", new { id = adquirente.Id }, adquirente));
        }
Esempio n. 4
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Codigo,Descricao")] Adquirente adquirente)
        {
            if (id != adquirente.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(adquirente);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AdquirenteExists(adquirente.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(adquirente));
        }
Esempio n. 5
0
        public async Task <IActionResult> Create([Bind("Id,Codigo,Descricao")] Adquirente adquirente)
        {
            if (ModelState.IsValid)
            {
                _context.Add(adquirente);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(adquirente));
        }
Esempio n. 6
0
        private decimal RealizaCalculoTaxasTransacao(TransacaoTaxas transacaoTaxas, Adquirente adquirente)
        {
            if (transacaoTaxas.bandeira.Equals(VISA))
            {
                adquirente.ObtemTaxasVisa();
            }
            else
            {
                adquirente.ObtemTaxasMaster();
            }
            decimal valorTaxaAdquirenteBandeira = adquirente.Taxas[0].ObtemTaxaTransacao(transacaoTaxas.tipoTransacao);

            return(transacaoTaxas.calculaValorTaxa(valorTaxaAdquirenteBandeira));
        }
 public async Task <IActionResult> Post(Adquirente adquirente)
 {
     try
     {
         _repo.Add(adquirente);
         if (await _repo.SaveChangesAsync())
         {
             return(Created($"/api/Adquirente/{adquirente.AdquirenteId}", adquirente));
         }
     }
     catch (System.Exception)
     {
         return(this.StatusCode(StatusCodes.Status500InternalServerError, "Banco de dados falhou"));
     }
     return(BadRequest());
 }
Esempio n. 8
0
        public decimal ObtemValorLiquidoTransacao(TransacaoTaxas transacaoTaxas)
        {
            Type adquirenteObj = Assembly.GetEntryAssembly().GetType("DotNetCore2RestWebApplication.Models." + transacaoTaxas.adquirente);

            if (adquirenteObj != null)
            {
                object     entity     = Activator.CreateInstance(adquirenteObj);
                Adquirente adquirente = ((Adquirente)entity);
                _logger.LogInformation("Processamento de consulta do ValorLiquidoAdquirente realizado com sucesso");
                return(RealizaCalculoTaxasTransacao(transacaoTaxas, adquirente));
            }
            else
            {
                return(Decimal.Zero);
            }
        }
Esempio n. 9
0
        public TransactionResultViewModel calculaValorLiquido(TransactionViewModel transactionViewModel)
        {
            Adquirente adquirente = adquirenteService.GetByid(transactionViewModel);

            if (adquirente == null)
            {
                return new TransactionResultViewModel()
                       {
                           Success = false, Message = "adquirente não encontrado"
                       }
            }
            ;

            var findTaxa = adquirente.Taxas.Where(x => x.Bandeira.ToString().Equals(transactionViewModel.Bandeira.ToLower()));

            if (!findTaxa.Any())
            {
                return new TransactionResultViewModel()
                       {
                           Success = false, Message = "bandeira não encontrada"
                       }
            }
            ;

            findTaxa = findTaxa.Where(x => x.TipoTransacao.ToString().Equals(transactionViewModel.Tipo.ToLower()));

            if (!findTaxa.Any())
            {
                return new TransactionResultViewModel()
                       {
                           Success = false, Message = "tipo operação não encontrado"
                       }
            }
            ;

            float taxa         = findTaxa.First().Taxa;
            float ValorLiquido = transactionViewModel.Valor * (1 - (taxa / 100));

            return(new TransactionResultViewModel()
            {
                Success = true,
                ValorLiquido = ValorLiquido
            });
        }
    }
}
Esempio n. 10
0
        public ICollection <Adquirente> GetAll()
        {
            Adquirente adquirenteA = new Adquirente("A", "Adquirente A");
            Adquirente adquirenteB = new Adquirente("C", "Adquirente B");
            Adquirente adquirenteC = new Adquirente("C", "Adquirente C");

            adquirenteA.Taxas = GetTaxasAdquirenteA();
            adquirenteB.Taxas = GetTaxasAdquirenteB();
            adquirenteC.Taxas = GetTaxasAdquirenteC();

            List <Adquirente> lstAdquirentes = new List <Adquirente>();

            lstAdquirentes.Add(adquirenteA);
            lstAdquirentes.Add(adquirenteB);
            lstAdquirentes.Add(adquirenteC);

            return(lstAdquirentes);
        }
Esempio n. 11
0
        public async Task <IActionResult> ObtemMdrAdquirente(string adquirente)
        {
            try
            {
                var        result        = _transacaoTaxasService.ObtemMdrAdquirente(adquirente);
                Adquirente adquirenteObj = result;

                if (adquirenteObj != null)
                {
                    await Task.Run(() => adquirenteObj);

                    return(Ok(adquirenteObj));
                }
                else
                {
                    return(NotFound());
                }
            }catch (Exception e)
            {
                _logger.LogInformation("Ocorreu um erro ao processar consulta MDR. " + e.Message);
                return(NoContent());
            }
        }
Esempio n. 12
0
        public async Task <IActionResult> Post(Arquivo arquivo)
        {
            try
            {
                string fileName    = "";
                string fileContent = "";
                if (arquivo.fileBytes != null && arquivo.fileBytes.Length > 0)
                {
                    fileName    = ArquivoHelper.ConvertBytesToFile(BASE_DIRECTORY_FILES, arquivo.fileBytes);
                    fileContent = ArquivoHelper.ReadFileContent(BASE_DIRECTORY_FILES, fileName);
                }
                else
                {
                    fileContent = arquivo.Nome;
                }


                var      arquivoPrevisto = new Arquivo();
                var      adquirente = new Adquirente();
                long     nroSequencial = 0;
                string   adquirenteNome = "";
                long     estabelecimento = 0;
                DateTime dataProcessamento, periodoIni, periodoFim;
                if (!string.IsNullOrEmpty(fileContent))
                {
                    int tipo = int.Parse(fileContent.Substring(0, 1));
                    switch (tipo)
                    {
                    // tipo '0'
                    case 0:
                        estabelecimento   = long.Parse(fileContent.Substring(1, 10));
                        dataProcessamento = new DateTime(int.Parse(fileContent.Substring(11, 4)),
                                                         int.Parse(fileContent.Substring(15, 2)),
                                                         int.Parse(fileContent.Substring(17, 2)));
                        periodoIni = new DateTime(int.Parse(fileContent.Substring(19, 4)),
                                                  int.Parse(fileContent.Substring(23, 2)),
                                                  int.Parse(fileContent.Substring(25, 2)));
                        periodoFim = new DateTime(int.Parse(fileContent.Substring(27, 4)),
                                                  int.Parse(fileContent.Substring(31, 2)),
                                                  int.Parse(fileContent.Substring(33, 2)));
                        nroSequencial  = long.Parse(fileContent.Substring(35, 7));
                        adquirenteNome = fileContent.Substring(42, 8);
                        adquirente     = await _repo.GetAdquirenteByName(adquirenteNome);

                        arquivoPrevisto = await _repo.GetArquivoByDataPrevisaoEAdquirenteId(dataProcessamento, adquirente.AdquirenteId);

                        if (adquirente != null && arquivoPrevisto != null && !string.IsNullOrEmpty(fileContent))
                        {
                            arquivoPrevisto.TipoRegistro      = 0;
                            arquivoPrevisto.Estabelecimento   = estabelecimento;
                            arquivoPrevisto.PeriodoInicial    = periodoIni;
                            arquivoPrevisto.PeriodoFinal      = periodoFim;
                            arquivoPrevisto.DataProcessamento = dataProcessamento;
                            arquivoPrevisto.Baixado           = true;
                            arquivoPrevisto.ArquivoLocalPath  = $"{BASE_DIRECTORY_FILES}/files/{fileName}";
                            arquivoPrevisto.ArquivoBackupPath = $"{BASE_DIRECTORY_FILES}/filesBackup/{fileName}";
                            arquivoPrevisto.NroSequencial     = nroSequencial;
                        }
                        break;

                    // tipo '1'
                    case 1:
                        dataProcessamento = new DateTime(int.Parse(fileContent.Substring(1, 4)),
                                                         int.Parse(fileContent.Substring(5, 2)),
                                                         int.Parse(fileContent.Substring(7, 2)));
                        estabelecimento = long.Parse(fileContent.Substring(9, 8));
                        adquirenteNome  = fileContent.Substring(17, 12);
                        nroSequencial   = long.Parse(fileContent.Substring(29, 7));

                        adquirente = await _repo.GetAdquirenteByName(adquirenteNome);

                        arquivoPrevisto = await _repo.GetArquivoByDataPrevisaoEAdquirenteId(dataProcessamento, adquirente.AdquirenteId);

                        if (adquirente != null && arquivoPrevisto != null && !string.IsNullOrEmpty(fileContent))
                        {
                            arquivoPrevisto.TipoRegistro      = 1;
                            arquivoPrevisto.Estabelecimento   = estabelecimento;
                            arquivoPrevisto.DataProcessamento = dataProcessamento;
                            arquivoPrevisto.Baixado           = true;
                            arquivoPrevisto.ArquivoLocalPath  = $"{AppDomain.CurrentDomain.BaseDirectory}/files/{fileName}";
                            arquivoPrevisto.ArquivoBackupPath = $"{AppDomain.CurrentDomain.BaseDirectory}/filesBackup/{fileName}";
                            arquivoPrevisto.NroSequencial     = nroSequencial;
                        }
                        break;
                    }



                    if (await _repo.SaveChangesAsync())
                    {
                        return(Created($"/api/Arquivo/{arquivoPrevisto.ArquivoId}", arquivoPrevisto));
                    }
                }
            }
            catch (System.Exception ex)
            {
                string message = ex.Message;
                return(this.StatusCode(StatusCodes.Status500InternalServerError, "Requisição falhou!"));
            }
            return(BadRequest());
        }