public JsonResponseResult SearchBing(string query) { // Construct the URI of the search request var uriQuery = uriBase + "?q=" + Uri.EscapeDataString(query); // Perform the Web request and get the response WebRequest request = HttpWebRequest.Create(uriQuery); request.Headers["Ocp-Apim-Subscription-Key"] = _ACCESSKEy; HttpWebResponse response = (HttpWebResponse)request.GetResponseAsync().Result; string json = new StreamReader(response.GetResponseStream()).ReadToEnd(); // Create result object for return var searchResult = new JsonResponseResult() { jsonResult = json, relevantHeaders = new Dictionary <String, String>() }; // Extract Bing HTTP headers foreach (String header in response.Headers) { if (header.StartsWith("BingAPIs-") || header.StartsWith("X-MSEdge-")) { searchResult.relevantHeaders[header] = response.Headers[header]; } } return(searchResult); }
public virtual JsonResult SearchBing(string query) { JsonResponseResult result = new JsonResponseResult(); ApiHelper helper = new ApiHelper(); result = helper.SearchBing(query); return(Json(result, JsonRequestBehavior.AllowGet)); }
public JsonResult SaveFile(FormCollection form) { var result = new JsonResponseResult <UpLoadFile>(); var customerCode = form["CustomerCode"]; try { if (!string.IsNullOrWhiteSpace(customerCode)) { string filePath = sysConfig.VoucherPath + customerCode + @"\"; if (!Directory.Exists(filePath)) { Directory.CreateDirectory(filePath); } HttpFileCollectionBase files = HttpContext.Request.Files; string tempName = string.Empty; for (int iFile = 0; iFile < files.Count; iFile++) { HttpPostedFileBase postedFile = files[iFile]; tempName = Path.GetFileName(postedFile.FileName); if (string.IsNullOrWhiteSpace(tempName)) { throw new Exception("请选择需要上传的文件"); } string fileExtension = Path.GetExtension(tempName); //if (fileExtension != ".xls") // throw new Exception("只能上传xls类型的文件"); if (!string.IsNullOrEmpty(tempName)) { tempName = DateTime.Now.ToString("yyyyMMddHHmmss") + fileExtension; postedFile.SaveAs(filePath + tempName); } } result.Result = "1"; result.ResultDesc = ""; result.Item = new UpLoadFile() { Address = tempName }; } else { result.Result = "0"; result.ResultDesc = "没有选择客户"; } } catch (Exception ex) { result.Result = "0"; result.ResultDesc = ex.Message; } return(Json(result, JsonRequestBehavior.DenyGet)); }
protected T CreateEmptyJsonResponse <T>(JsonResponseResult result, string id = "") where T : BaseJsonResponse, new() { var jsonResponse = new T { Data = id, Code = result }; return(jsonResponse); }
public JsonResult GetSettlementList(string customerCode) { var result = new JsonResponseResult <SettlementJson>(); try { var model = new SettlementJson(); int totalNumber = 0; decimal totalFee = 0; decimal totalSettleWeight = 0; decimal totalWeight = 0; _settlementService.GetSettlementByCustomerCode(customerCode, Settlement.StatusEnum.Outstanding).ForEach( p => { model.Data.Add(new SettlementJsonModel { CreatedBy = p.CreatedBy, CreatedOn = p.CreatedOn.ToString("yyyy-MM-dd HH:mm:ss"), CustomerCode = p.CustomerCode, SettlementNumber = p.SettlementNumber, TotalNumber = p.TotalNumber, TotalFee = p.TotalFee.ToString("F2"), TotalSettleWeight = p.TotalSettleWeight.ToString("F3"), TotalWeight = p.TotalWeight.ToString("F3") }); totalNumber = totalNumber + p.TotalNumber; totalFee = totalFee + p.TotalFee; totalSettleWeight = totalSettleWeight + p.TotalSettleWeight; totalWeight = totalWeight + p.TotalWeight; }); model.TotalFee = totalFee.ToString("F2"); model.TotalNumber = totalNumber; model.TotalSettleWeight = totalSettleWeight.ToString("F3"); model.TotalWeight = totalWeight.ToString("F3"); result.Result = "1"; result.ResultDesc = ""; result.Item = model; } catch (Exception ex) { Log.Exception(ex); result.Result = "0"; result.ResultDesc = ""; } return(Json(result, JsonRequestBehavior.AllowGet)); }
public JsonResult GetUserList(string keyword) { var result = new JsonResponseResult <List <CustomerSmallExt> >(); try { var model = _settlementService.GetOutstandingPaymentCustomer(keyword); result.Result = "1"; result.ResultDesc = ""; result.Item = model; } catch (Exception ex) { Log.Exception(ex); result.Result = "0"; result.ResultDesc = ""; } return(Json(result, JsonRequestBehavior.AllowGet)); }