예제 #1
0
 public IActionResult Post([FromBody] Moeda moeda)
 {
     try
     {
         var taxa = cambioServico.PegarTaxa(moeda.Codigo);
     }
     catch (Exception)
     {
         return(BadRequest(new ApiCasoDeUsoSaida.Padrao()
         {
             Mensagem = "Moeda inválida"
         }));
     }
     if (moedaRepositorio.Seleciona(moeda.Id) != null)
     {
         return(BadRequest(new ApiCasoDeUsoSaida.Padrao()
         {
             Mensagem = "Moeda já existe"
         }));
     }
     moedaRepositorio.Insere(moeda);
     return(Created("", new ApiCasoDeUsoSaida.Padrao()
     {
         Mensagem = "Moeda criada com sucesso",
     }));
 }
예제 #2
0
        public CambioCasoDeUsoSaida Calcular(CambioCasoDeUsoEntrada obj)
        {
            Moeda    moeda    = moedaRepositorio.Seleciona(obj.MoedaId);
            Segmento segmento = segmentoRepositorio.Seleciona(obj.SegmentoId);

            if (moeda == null || segmento == null)
            {
                throw new System.Exception("Parâmetros incorretos");
            }
            double taxa = cambioServico.PegarTaxa(moeda.Codigo);

            return(new CambioCasoDeUsoSaida
            {
                Valor = (obj.Quantidade * taxa) * (1 + segmento.Taxa)
            });
        }