Exemplo n.º 1
0
        public async Task <IActionResult> Post([FromBody] EnvelopeModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            int  organizationId    = 0;
            var  organizationIdVal = User.FindFirst(ClaimTypes.Country)?.Value;
            bool isValid           = int.TryParse(organizationIdVal, out organizationId);

            if (organizationId == 0)
            {
                return(BadRequest("A bad attempt to access the envelope"));
            }

            decimal exchangeRate = 1;
            var     dated        = DateTime.Now;
            var     rates        = await exchangeRateService.GetCurrencyRatesForDate(dated);

            if (rates.Rates == null)
            {
                string apiKey = exchangeRateService.GetAPIKeyForOpenExchange();
                rates = await exchangeRateHttpService.GetRatesAsync(apiKey);

                if (rates.Rates != null)
                {
                    await exchangeRateService.SaveCurrencyRatesAsync(rates.Rates, DateTime.Now);

                    exchangeRate = currencyService.GetExchangeRateForCurrency(model.Currency, rates.Rates);
                }
            }
            else
            {
                exchangeRate = currencyService.GetExchangeRateForCurrency(model.Currency, rates.Rates);
            }
            model.ExchangeRate = exchangeRate;
            var response = await envelopeService.AddAsync(model, organizationId);

            if (!response.Success)
            {
                return(BadRequest(response.Message));
            }
            return(Ok(true));
        }
        public async Task <IActionResult> GetLatestRates()
        {
            ExchangeRatesView ratesView = null;
            int count = ratesService.GetAPIsCallsCount();

            if (count >= 999)
            {
                return(Ok(null));
            }

            ratesView = await ratesService.GetLatestCurrencyRates();

            if (ratesView.Rates == null)
            {
                string apiKey = ratesService.GetAPIKeyForOpenExchange();
                ratesView = await ratesHttpService.GetRatesAsync(apiKey);

                if (ratesView.Rates != null)
                {
                    await ratesService.SaveCurrencyRatesAsync(ratesView.Rates, DateTime.Now);
                }
            }
            return(Ok(ratesView));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> GetProjectsBudgetSummaryReport()
        {
            var defaultCurrencyObj = currencyService.GetDefaultCurrency();

            if (defaultCurrencyObj == null)
            {
                return(BadRequest("Default currency is not set. Please contact administrator"));
            }

            string  defaultCurrency = defaultCurrencyObj.Currency;
            decimal exchangeRate    = 1;

            if (!string.IsNullOrEmpty(defaultCurrency))
            {
                var dated = DateTime.Now;
                var rates = await ratesService.GetCurrencyRatesForDate(dated);

                if (rates.Rates == null)
                {
                    string apiKey = ratesService.GetAPIKeyForOpenExchange();
                    rates = await ratesHttpService.GetRatesAsync(apiKey);

                    if (rates.Rates != null)
                    {
                        await ratesService.SaveCurrencyRatesAsync(rates.Rates, DateTime.Now);

                        exchangeRate = reportService.GetExchangeRateForCurrency(defaultCurrency, rates.Rates);
                    }
                }
                else
                {
                    exchangeRate = reportService.GetExchangeRateForCurrency(defaultCurrency, rates.Rates);
                }
            }
            var report = await reportService.GetProjectsBudgetReportSummary(clientUrl, defaultCurrency, exchangeRate);

            report.ReportSettings.DefaultCurrency = defaultCurrency;
            var response = excelService.GenerateProjectBudgetReportSummary(report);

            if (response.Success)
            {
                report.ReportSettings.ExcelReportName = response.Message;
            }
            return(Ok(report));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Get()
        {
            var defaultCurrencyObj = currencyService.GetDefaultCurrency();

            if (defaultCurrencyObj == null)
            {
                return(BadRequest("Default currency is not set. Please contact administrator"));
            }

            string  defaultCurrency = defaultCurrencyObj.Currency;
            decimal exchangeRate    = 1;

            if (!string.IsNullOrEmpty(defaultCurrency))
            {
                var dated = DateTime.Now;
                var rates = await ratesService.GetCurrencyRatesForDate(dated);

                if (rates.Rates == null)
                {
                    string apiKey = ratesService.GetAPIKeyForOpenExchange();
                    rates = await ratesHttpService.GetRatesAsync(apiKey);

                    if (rates.Rates != null)
                    {
                        await ratesService.SaveCurrencyRatesAsync(rates.Rates, DateTime.Now);

                        exchangeRate = projectService.GetExchangeRateForCurrency(defaultCurrency, rates.Rates);
                    }
                }
                else
                {
                    exchangeRate = projectService.GetExchangeRateForCurrency(defaultCurrency, rates.Rates);
                }
            }
            var projects = projectService.GetAll(exchangeRate);

            return(Ok(projects));
        }