/// <summary>
        /// Following Common method is created to set parameter to call report API.
        /// </summary>
        /// <param name="DbName"></param>
        /// <param name="StartDate"></param>
        /// <param name="EndDate"></param>
        //TO DO:Currenly This method is used only in Chart Method of this controller, for other method we will implement it letter.
        /// <returns></returns>
        private APIParameters SetApiParameters(string DbName, string StartDate, string EndDate)
        {
            RevenuePlanner.Services.ICurrency objCurrency = new RevenuePlanner.Services.Currency();
            APIParameters objApiParameters = new APIParameters();


            if (!string.IsNullOrEmpty(DbName) && DbName == Convert.ToString(Enums.ApplicationCode.RPC))
            {
                objApiParameters.ConnectionString = Sessions.User.UserApplicationId.Where(o => o.ApplicationTitle.ToLower() == Convert.ToString(Enums.ApplicationCode.RPC).ToLower()).Select(o => o.ConnectionString).FirstOrDefault();
            }
            else if (!string.IsNullOrEmpty(DbName) && DbName.ToLower() == Convert.ToString(Enums.ApplicationCode.MRP).ToLower())
            {
                if (!string.IsNullOrEmpty(Convert.ToString(ConfigurationManager.ConnectionStrings["MRPEntities"])))
                {
                    string efConnectionString             = Convert.ToString(ConfigurationManager.ConnectionStrings["MRPEntities"]);
                    EntityConnectionStringBuilder builder = new EntityConnectionStringBuilder(efConnectionString);
                    string regularConnectionString        = builder.ProviderConnectionString;

                    if (!string.IsNullOrEmpty(regularConnectionString))
                    {
                        objApiParameters.ConnectionString = Convert.ToString(regularConnectionString.Replace(@"\", @"\\"));
                    }
                }
            }

            if (ConfigurationManager.AppSettings.Count > 0)
            {
                if (!string.IsNullOrEmpty(Convert.ToString(ConfigurationManager.AppSettings["AuthorizedReportAPIUserName"])))
                {
                    objApiParameters.AuthorizedReportAPIUserName = System.Configuration.ConfigurationManager.AppSettings.Get("AuthorizedReportAPIUserName");
                }
                if (!string.IsNullOrEmpty(Convert.ToString(ConfigurationManager.AppSettings["AuthorizedReportAPIPassword"])))
                {
                    objApiParameters.AuthorizedReportAPIPassword = System.Configuration.ConfigurationManager.AppSettings.Get("AuthorizedReportAPIPassword");
                }
                if (!string.IsNullOrEmpty(Convert.ToString(ConfigurationManager.AppSettings["IntegrationApi"])))
                {
                    objApiParameters.ApiUrl = System.Configuration.ConfigurationManager.AppSettings.Get("IntegrationApi");
                    if (!string.IsNullOrEmpty(objApiParameters.ApiUrl) && !objApiParameters.ApiUrl.EndsWith("/"))
                    {
                        objApiParameters.ApiUrl += "/";
                    }
                }
                List <RevenuePlanner.Models.CurrencyModel.ClientCurrency> MonthWiseUserReportCurrency = objCurrency.GetUserCurrencyMonthwise(StartDate, EndDate);
                //string[] CurrencyRate = null;
                if (MonthWiseUserReportCurrency != null)
                {
                    objApiParameters.CurrencyRate = new string[MonthWiseUserReportCurrency.Count];
                    int i = 0;
                    foreach (var item in MonthWiseUserReportCurrency)
                    {
                        objApiParameters.CurrencyRate[i] = item.StartDate.ToString("MM/dd/yyyy") + ":" + item.EndDate.ToString("MM/dd/yyyy") + ":" + item.ExchangeRate + ":" + item.CurrencySymbol;
                        i++;
                    }
                }
            }
            return(objApiParameters);
        }
Exemplo n.º 2
0
        public APIResult CallLogoutAPI(string apiURL, string userName)
        {
            List <APIParameters> apiParameters = new List <APIParameters>();
            var userParameter = new APIParameters()
            {
                Key   = "email",
                Value = userName,
                Type  = APIParameterType.Body
            };

            var cpuIDParameter = new APIParameters()
            {
                Key   = "CPUId",
                Value = GenHelper.cpuId(),
                Type  = APIParameterType.Body
            };
            var macAddressParameter = new APIParameters()
            {
                Key   = "mac",
                Value = GenHelper.GetMACAddress(),
                Type  = APIParameterType.Body
            };
            var app_idParameter = new APIParameters()
            {
                Key   = "app_id",
                Value = "LICAPPID",
                Type  = APIParameterType.Body
            };

            var motherBoardIdParameter = new APIParameters()
            {
                Key   = "MotherBoardId",
                Value = GenHelper.motherBoardId(),
                Type  = APIParameterType.Body
            };

            var diskIdParameter = new APIParameters()
            {
                Key   = "DiskId",
                Value = GenHelper.diskId(),
                Type  = APIParameterType.Body
            };

            apiParameters.Add(userParameter);
            apiParameters.Add(cpuIDParameter);
            apiParameters.Add(macAddressParameter);
            apiParameters.Add(app_idParameter);
            apiParameters.Add(motherBoardIdParameter);
            apiParameters.Add(diskIdParameter);

            var result = ApiIntegration.callPostAPI(apiURL, apiParameters);

            return(result);
        }
        //IsChartTable Parameter is Added to check Method is called to get Chart or ChartTable.
        /// <summary>
        ///
        /// </summary>
        /// <param name="Id">Report Graph Id</param>
        /// <param name="DbName">This parameter is used to check this method is called for plan report or measure reports</param>
        /// <param name="Container"></param>
        /// <param name="SDV">Selected filters value</param>
        /// <param name="TopOnly">Chart or Charttable will be return or row or Configured default rows</param>
        /// <param name="ViewBy">Selected view by ie.'Quarter','Month'</param>
        /// <param name="StartDate"></param>
        /// <param name="EndDate"></param>
        /// <param name="IsViewData">To Check this method is called from dashboard or on click of viewdata.</param>
        /// <param name="isChartTable">To Check this method will return Chart Table or Chart</param>
        public async Task <ActionResult> GetChart(int Id, string DbName, string Container, string[] SDV, bool TopOnly = true, string ViewBy = "Q", string StartDate = "01/01/1900", string EndDate = "01/01/2100", bool IsViewData = false, bool isChartTable = false)
        {
            HttpResponseMessage response = new HttpResponseMessage();
            string result = string.Empty;

            Sessions.ViewByValue = ViewBy;
            if (ConfigurationManager.AppSettings.Count > 0)
            {
                try
                {
                    if (Id > 0)
                    {
                        //Using following method required parametr for Report API will be set.
                        APIParameters objApiParameters    = SetApiParameters(DbName, StartDate, EndDate);
                        HttpClient    client              = new HttpClient();
                        int           CommonWebAPITimeout = 0;
                        string        strwebAPITimeout    = System.Configuration.ConfigurationManager.AppSettings["CommonIntegrationWebAPITimeOut"];
                        if (!string.IsNullOrEmpty(strwebAPITimeout))
                        {
                            CommonWebAPITimeout = Convert.ToInt32(strwebAPITimeout);
                        }

                        client.Timeout = TimeSpan.FromHours(CommonWebAPITimeout); //set timeout for Common Integration API call
                        client.Timeout = TimeSpan.FromMinutes(5);                 //set timeout for Common Integration API call

                        Uri baseAddress = new Uri(objApiParameters.ApiUrl);
                        client.BaseAddress = baseAddress;

                        ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); };

                        ReportParameters objParams = new ReportParameters();
                        objParams.Id = Id;
                        objParams.ConnectionString = objApiParameters.ConnectionString;
                        objParams.Container        = Container;
                        objParams.SDV          = SDV;
                        objParams.TopOnly      = TopOnly;
                        objParams.ViewBy       = ViewBy;
                        objParams.StartDate    = StartDate;
                        objParams.EndDate      = EndDate;
                        objParams.UserName     = objApiParameters.AuthorizedReportAPIUserName;
                        objParams.Password     = objApiParameters.AuthorizedReportAPIPassword;
                        objParams.CurrencyRate = objApiParameters.CurrencyRate;
                        //Following parameter is added to check this method is called from view data or not and pass this parameter in to report API.
                        objParams.IsViewData = IsViewData;
                        //Following will be return chart or table based on passed parameter isChartTable
                        if (isChartTable == false)
                        {
                            response = await client.PostAsJsonAsync("api/Report/Chart ", objParams);
                        }
                        else
                        {
                            response = await client.PostAsJsonAsync("api/Report/GetChartTable", objParams);
                        }

                        result = response.Content.ReadAsStringAsync().Result;
                    }
                }
                catch (Exception ex)
                {
                    ErrorSignal.FromCurrentContext().Raise(ex);
                }
            }
            return(Json(new { isSuccess = true, data = result }, JsonRequestBehavior.AllowGet));
        }