Exemple #1
0
 public IList <TaxModel> GetTax()
 {
     try
     {
         List <Tax> taxs = _taxRepository.GetTax();
         // var items = products.ToList();
         return(taxs?.Select(x =>
                             new TaxModel(x.Id, x.TaxDetail, x.Rate, x.CreatedDate, x.ModifiedDate, x.ModifiedBy, x.CreatedBy)
                             ).ToList());
     }
     catch (Exception ex)
     {
         fault.Result       = false;
         fault.ErrorMessage = "Error in GetTax method";
         fault.ErrorDetails = ex.ToString();
         throw new FaultException <FaultData>(fault);
     }
 }
Exemple #2
0
        public async Task <Exchange> GetQuote(string category, string currency, decimal qty)
        {
            try
            {
                _logger.LogInformation($"Calculando a conversão para {currency}. (qty = {qty})");

                var result = await Task.WhenAll(
                    _factorRepository.GetFactor(currency),
                    _taxRepository.GetTax(category));

                var factor = result[0];

                if (factor == 0)
                {
                    throw new FactorNotFoundException($"Fator não encontrado para a moeda {currency}.");
                }

                var tax = result[1];

                if (tax == 0)
                {
                    throw new TaxNotFoundException($"Taxa não encontrado para a categoria {category}.");
                }

                var total = Math.Round(qty * factor * (1 + tax), 2);

                _logger.LogInformation($"Resultado da conversão: {total}");

                return(new Exchange
                {
                    ValueRequested = qty,
                    FactorApplied = factor,
                    TaxApplied = tax,
                    Total = total
                });
            }
            catch (TaxNotFoundException ex)
            {
                _logger.LogError(ex, ex.Message);
                throw ex;
            }
            catch (FactorNotFoundException ex)
            {
                _logger.LogError(ex, ex.Message);
                throw ex;
            }
            catch (Exception ex)
            {
                var message = "Houve um erro inesperado";
                _logger.LogError(ex, message);
                throw new ExchangeServiceException($"{message}: {ex.Message}", ex.InnerException);
            }
        }
 public decimal GetTax(string city, string dateString)
 {
     try
     {
         var date = DateTime.Parse(dateString);
         return(_taxRepository.GetTax(city, date));
     }
     catch (Exception e)
     {
         throw new ArgumentException($"Invalid date provided ({dateString})");
     }
 }
Exemple #4
0
        public async Task <TaxResponse> GetTax(TaxRequest taxRequest)
        {
            var taxSetupResult = await _taxRepository.GetTax(taxRequest);

            var taxAmount = TaxRuleFactory.GetTaxRule(taxRequest.municipalityName)?.ApplyRule(taxSetupResult);

            return(new TaxResponse
            {
                municipilityName = taxRequest?.municipalityName,
                taxRate = taxAmount,
                message = !taxSetupResult.Any() ? "No result found." : String.Empty
            });
        }
        public TaxResponse TaxRate(string state)
        {
            TaxResponse response = new TaxResponse();

            response.Tax = _taxRepository.GetTax(state);

            if (response.Tax == null)
            {
                response.Success = false;
                response.Message = $"{state} is an invalid State";
            }
            else
            {
                response.Success = true;
            }
            return(response);
        }
Exemple #6
0
 public async Task <IEnumerable <Tax> > GetTaxAsync()
 {
     return(await _taxRepository.GetTax());
 }