public async Task <IActionResult> GetEnvelopeReport([FromBody] SearchEnvelopeModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } 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.GetEnvelopeReport(model, clientUrl, defaultCurrency, exchangeRate); report.ReportSettings.DefaultCurrency = defaultCurrency; var response = excelService.GenerateEnvelopeReport(report); if (response.Success) { report.ReportSettings.ExcelReportName = response.Message; } return(Ok(report)); }
public string GetQueryStringForEnvelopeReport(SearchEnvelopeModel model) { string queryString = "?load=true"; if (model.FunderTypeIds.Count > 0) { string funderTypeIdsStr = string.Join(",", model.FunderTypeIds); queryString += ("&ftypes=" + funderTypeIdsStr); } if (model.FunderIds.Count > 0) { queryString += "&funders=" + string.Join(",", model.FunderIds); } if (model.EnvelopeTypeIds.Count > 0) { string envelopeTypeIdsStr = string.Join(",", model.EnvelopeTypeIds); queryString += ("&envelopeTypes=" + envelopeTypeIdsStr); } if (model.StartingYear > 0) { queryString += ("&syear=" + model.StartingYear); } if (model.EndingYear > 0) { queryString += ("&eyear=" + model.EndingYear); } if (model.ChartType > 0) { queryString += ("&ctype=" + model.ChartType); } return(queryString); }