public async Task <JsonResult> Get(string targetUrl, dynamic data) { try { string token = Request.Cookies["MAQTA-LOCAL-TOKEN"].Value; ViewBag.LoginURL = Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["MamarBaseUrl"]); var customHeadersList = new Dictionary <string, string>(); var cCodeVal = !string.IsNullOrEmpty(Request.Headers["CCode"]) ? Request.Headers["CCode"].ToString() : string.Empty; var uCodeVal = !string.IsNullOrEmpty(Request.Headers["UCode"]) ? Request.Headers["UCode"].ToString() : string.Empty; customHeadersList.Add("CCode", cCodeVal); customHeadersList.Add("UCode", uCodeVal); //ITokenContainer tokenContainer = new TokenContainer(); if (token == null) { return(Json(new { redirectUrl = Url.Action("LogOff", "Account"), isRedirect = true }, JsonRequestBehavior.AllowGet)); } string queryString = string.Empty; string dataString = ((string[])data)[0]; if (!string.IsNullOrEmpty(dataString)) { var dataParams = JObject.Parse(dataString); string[] properties = new string[dataParams.Count]; var i = 0; foreach (var param in dataParams) { properties[i] = (string.Format("{0}={1}", param.Key, HttpUtility.JavaScriptStringEncode(param.Value.Value <string>()))); i++; } queryString = string.Join("&", properties); } ApiHelper.Client.ApiClient client = new ApiHelper.Client.ApiClient(HttpClientInstance.Instance, token); GenericClient cb = new GenericClient(client); var response = await cb.Get(targetUrl + "?" + queryString, customHeadersList); return(new JsonResult() { Data = response, ContentType = "application/json", MaxJsonLength = Int32.MaxValue, JsonRequestBehavior = JsonRequestBehavior.AllowGet }); // Json(response, JsonRequestBehavior.AllowGet); } catch (Exception ex) { CentralELKLogger._errorlog.Error(ex, "MAMAR modul Error: " + ex.Message + " User Name " + User.Identity.GetUserName()); throw ex; } }
public async Task <ActionResult> DownloadReport(string targetUrl, string CCode, string UCode, string ReportParameter) { // ITokenContainer tokenContainer = new TokenContainer(); string token = Request.Cookies["MAQTA-LOCAL-TOKEN"].Value; if (token == null) { return(Json(new { redirectUrl = Url.Action("LogOff", "Account"), isRedirect = true }, JsonRequestBehavior.AllowGet)); } ApiHelper.Client.ApiClient client = new ApiHelper.Client.ApiClient(HttpClientInstance.Instance, token); GenericClient cb = new GenericClient(client); var response = await cb.Get(targetUrl); JavaScriptSerializer j = new JavaScriptSerializer(); ADP.MG.Pcs.Models.EntityModels.Report reportModel = default(ADP.MG.Pcs.Models.EntityModels.Report); if (!string.IsNullOrEmpty((response.ResponseResult))) { reportModel = Newtonsoft.Json.JsonConvert.DeserializeObject <ADP.MG.Pcs.Models.EntityModels.Report>(response.ResponseResult); } //var typeReportSource = new UriReportSource { Uri = string.Format("Reports/{0}", reportModel.ReportFileName) }; var typeReportSource = new UriReportSource { Uri = string.Format("Report/{0}", "CustomReport.trdx") }; string[] parameters; parameters = ReportParameter.ToString().Split(';'); typeReportSource.Parameters.Add("centerCode", parameters[0]); typeReportSource.Parameters.Add("jobNumber", parameters[1]); typeReportSource.Parameters.Add("searchString", parameters[2]); typeReportSource.Parameters.Add("pageNumber", parameters[3]); typeReportSource.Parameters.Add("pageSize", parameters[4]); typeReportSource.Parameters.Add("CCode", CCode); typeReportSource.Parameters.Add("UCode", UCode); typeReportSource.Parameters.Add("token", token); Telerik.Reporting.Processing.ReportProcessor reportProcessor = new Telerik.Reporting.Processing.ReportProcessor(); //Telerik.Reporting.Processing.RenderingResult result = reportProcessor.RenderReport(reportModel.DownloadType.ToUpper(), typeReportSource, null); Telerik.Reporting.Processing.RenderingResult result = reportProcessor.RenderReport("XLS", typeReportSource, null); byte[] contents = result.DocumentBytes; //string mimeType = reportModel.DownloadType == "xls" ? "vnd.ms-excel" : "vnd.ms-excel";//reportModel.DownloadType; string mimeType = "vnd.ms-excel"; //reportModel.DownloadType; //return File(contents, string.Format("application/{0}", mimeType), reportModel.DownloadFileName); return(File(contents, string.Format("application/{0}", mimeType), "Chassis Details.xls")); }
public async Task <ActionResult> DownloadApprovalReport(string targetUrl, string CCode, string UCode, string ReportParameter) { //ITokenContainer tokenContainer = new TokenContainer(); string token = Request.Cookies["MAQTA-LOCAL-TOKEN"].Value;//Used this as Per Mudassar on 4-July-2019 if (token == null) { return(Json(new { redirectUrl = Url.Action("LogOff", "Account"), isRedirect = true }, JsonRequestBehavior.AllowGet)); } ApiHelper.Client.ApiClient client = new ApiHelper.Client.ApiClient(HttpClientInstance.Instance, token); GenericClient cb = new GenericClient(client); var response = await cb.Get(targetUrl); JavaScriptSerializer j = new JavaScriptSerializer(); ADP.MG.Pcs.Models.EntityModels.Report reportModel = default(ADP.MG.Pcs.Models.EntityModels.Report); if (!string.IsNullOrEmpty((response.ResponseResult))) { reportModel = Newtonsoft.Json.JsonConvert.DeserializeObject <ADP.MG.Pcs.Models.EntityModels.Report>(response.ResponseResult); } var typeReportSource = new UriReportSource { Uri = string.Format("Report/{0}", "Approval.trdx") }; string[] parameters; parameters = ReportParameter.ToString().Split(';'); typeReportSource.Parameters.Add("centerCode", parameters[0]); typeReportSource.Parameters.Add("jobNumber", parameters[1]); typeReportSource.Parameters.Add("CCode", CCode); typeReportSource.Parameters.Add("UCode", UCode); typeReportSource.Parameters.Add("token", token); Telerik.Reporting.Processing.ReportProcessor reportProcessor = new Telerik.Reporting.Processing.ReportProcessor(); Telerik.Reporting.Processing.RenderingResult result = reportProcessor.RenderReport("PDF", typeReportSource, null); byte[] contents = result.DocumentBytes; string mimeType = "PDF"; return(File(contents, string.Format("application/{0}", mimeType), "Approval.pdf")); }
public async Task <JsonResult> Get(string targetUrl, dynamic data) { try { var customHeadersList = new Dictionary <string, string>(); var selectedCompany = Request.Cookies["_selected_company_"]; ITokenContainer tokenContainer = new TokenContainer(); tokenContainer.ApiSelectedCompany = selectedCompany != null?Server.UrlDecode(selectedCompany.Value) : ""; var cSelectedCompany = !string.IsNullOrEmpty(Request.Headers["_selected_company_"]) ? Request.Headers["_selected_company_"].ToString() : string.Empty; customHeadersList.Add("_selected_company_", cSelectedCompany); string queryString = string.Empty; if (tokenContainer.ApiToken == null) { return(Json(new { redirectUrl = Url.Action("LogOff", "Account", new { area = string.Empty }), isRedirect = true }, JsonRequestBehavior.AllowGet)); } if (!string.IsNullOrEmpty(((string[])data)[0])) { var dataParams = JObject.Parse(((string[])data)[0]); List <string> properties = new List <string>(); foreach (var param in dataParams) { properties.Add(string.Format("{0}={1}", param.Key, HttpUtility.JavaScriptStringEncode(param.Value.Value <string>()))); } queryString = string.Join("&", properties.ToArray()); } ApiHelper.Client.ApiClient client = new ApiHelper.Client.ApiClient(HttpSubscriptionClient.Instance, tokenContainer); GenericClient cb = new GenericClient(client); var response = await cb.Get(targetUrl + "?" + queryString, customHeadersList); return(Json(response, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { throw ex; } }
public async Task <ActionResult> GetSubscriptionData() { string EnableSubscriptionFee = ConfigurationManager.AppSettings["EnableMamarSubscriptionFee"]; if (!string.IsNullOrEmpty(EnableSubscriptionFee) && EnableSubscriptionFee != "__EnableMamarSubscriptionFee__" && Convert.ToBoolean(EnableSubscriptionFee)) { string token = Request.Cookies["MAQTA-LOCAL-TOKEN"].Value; if (token == null) { return(Json(new { redirectUrl = Url.Action("LogOff", "Account"), isRedirect = true }, JsonRequestBehavior.AllowGet)); } ApiHelper.Client.ApiClient client = new ApiHelper.Client.ApiClient(HttpSubscriptionClient.Instance, token); GenericClient cb = new GenericClient(client); var response = await cb.Get("subscription/SubscriptionStatus"); var objSubscription = JsonConvert.DeserializeObject <SubscriptionStatusResponse>(response.ResponseResult); if (objSubscription.isRestricted) { return(Json(new ApiResponse() { StatusIsSuccessful = false, ResponseResult = "Subscription Disabled" }, JsonRequestBehavior.AllowGet)); } else { return(Json(response, JsonRequestBehavior.AllowGet)); } } else { return(Json(new ApiResponse() { StatusIsSuccessful = false, ResponseResult = "Subscription Disabled" }, JsonRequestBehavior.AllowGet)); } }