public async Task <IActionResult> GetYearWiseProjects([FromBody] SearchProjectsByYearModel 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.GetProjectsByYear(model, clientUrl, defaultCurrency, exchangeRate); report.ReportSettings.DefaultCurrency = defaultCurrency; var response = excelService.GenerateYearlyProjectsReport(report); if (response.Success) { report.ReportSettings.ExcelReportName = response.Message; } return(Ok(report)); }
public string GetQueryStringForTimeSeriesReport(SearchProjectsByYearModel model) { string queryString = "?load=true"; if (model.OrganizationIds.Count > 0) { queryString += "&orgs=" + string.Join(",", model.OrganizationIds); } if (model.LocationId > 0) { queryString += ("&locationId=" + model.LocationId); } if (model.SubLocationIds.Count > 0) { queryString += "&slocations=" + string.Join(",", model.SubLocationIds); } if (model.SectorIds.Count > 0) { string sectorIdsStr = string.Join(",", model.SectorIds); queryString += ("§ors=" + sectorIdsStr); } if (model.ProjectIds.Count > 0) { string projectIdsStr = string.Join(",", model.ProjectIds); queryString += ("&projects=" + projectIdsStr); } if (model.StartingYear > 0) { queryString += ("&syear=" + model.StartingYear); } if (model.EndingYear > 0) { queryString += ("&eyear=" + model.EndingYear); } if (model.MarkerId > 0) { queryString += ("&mid=" + model.MarkerId); } if (model.MarkerValues.Count > 0) { for (int m = 0; m < model.MarkerValues.Count; m++) { model.MarkerValues[m] = WebUtility.UrlEncode(model.MarkerValues[m]); } queryString += ("&mvalue=" + string.Join(",", model.MarkerValues)); } if (model.MarkerId2 > 0) { queryString += ("&mid2=" + model.MarkerId2); } if (model.MarkerValues2.Count > 0) { for (int m = 0; m < model.MarkerValues2.Count; m++) { model.MarkerValues2[m] = WebUtility.UrlEncode(model.MarkerValues2[m]); } queryString += ("&mvalue2=" + string.Join(",", model.MarkerValues2)); } if (model.ChartType > 0) { queryString += ("&ctype=" + model.ChartType); } return(queryString); }