public async Task <DownloadFilterBlockResponse> PostAsync(DownloadFilterBlock input) { DownloadFilterBlockResponse resp = new DownloadFilterBlockResponse(); string token = AppSettings.Settings.Token; string baseUrl = AppSettings.Settings.BaseUrl; string result; string hash = await GetBlockChainHashCodeController.GetBlockchainHash(); try { string filters = BuildFilters(input.BlockFilter); var client = new RestClient(baseUrl); var request = new RestRequest("downloadfilteredblock", Method.POST); request.AddParameter("TenantID", "0"); request.AddParameter("UserID", "0"); request.AddParameter("RequestingUserID", input.UserID); request.AddParameter("LedgerName", input.LedgerName); request.AddParameter("BlockProofHash", input.BlockProofHash); if (hash != null) { request.AddParameter("BlockchainProofHash", hash); } else { request.AddParameter("BlockchainProofHash", input.BlockchainProofHash); } request.AddParameter("BlockFilter", filters); request.AddParameter("BPAASToken", token, ParameterType.HttpHeader); IRestResponse response = await client.ExecuteAsync(request); result = response.Content; if (response != null) { var tempresult = JsonConvert.DeserializeObject <dynamic>(response.Content); if (response.StatusCode == System.Net.HttpStatusCode.OK) { try { JArray a = JArray.Parse(tempresult.ToString()); resp.searchResult = new List <BlockData>(); foreach (JObject o in a.Children <JObject>()) { string blockdata = string.Empty; string blockid = string.Empty; string blockname = string.Empty; foreach (JProperty p in o.Properties()) { string name = p.Name; //string value = (string)p.Value; if (name == "BpaaSPayload") { // result.Add(p.Value.ToString()); var temp = JsonConvert.DeserializeObject <dynamic>(p.Value.ToString()); blockdata = temp.ToString(); // patient = JsonConvert.DeserializeObject<PatientDto>(res.ToString()); } if (name == "BlockName") { blockname = p.Value.ToString(); } if (name == "BlockHashCode") { blockid = p.Value.ToString(); } //Console.WriteLine(name + " -- " + value); } BlockData res = new BlockData() { blockID = blockid, blockName = blockname, data = blockdata }; resp.searchResult.Add(res); } resp.success = true; } catch (Exception ex) { resp.message = "Fail to deserilaized the response"; resp.success = false; } } else { resp.success = false; resp.message = CleanUpErrroMessage(tempresult); } } else { resp.success = false; resp.message = "BPaaS Service retunred null response"; } //result.microbeTraceData.Add("{"Section1":{"Number":"1","Saved":false,"PatientInformation":{"IsNewCase":true,"Section":"1","CDCInformation":{"CaseState":"000001","CDC2019nCovID":"12345"},"Firstname":"Test","DateOfBirth":"2020-07-01T05:00:00.000Z","FormDateOfBirth":"2020-07-01T05:00:00.000Z","Lastname":"One"},"InterviewerInformation":{"Section":"1","UserProfile":{"IsLoggedIn":true,"BPaasInfo":{"TenantID":"0","UserID":"0","RequestingUserID":"4","LedgerName":"ContactTrace","BlockchainProofHash":"1bb3e7e7edd8ba0ef4aabb9c5c0227439032937ad162d1f6eda798c895f128e9"},"Firstname":"Test","Lastname":"Login","Email":"[email protected]”}}}}"); } catch (Exception e) { Console.WriteLine("{0} Exception caught.", e); resp.success = false; resp.message = e.Message; } return(resp); }
public async Task <AddBlockResponse> PostAsync(AddBlockDto input) { AddBlockResponse result = new AddBlockResponse(); string token = AppSettings.Settings.Token; string baseUrl = AppSettings.Settings.BaseUrl; string hash = await GetBlockChainHashCodeController.GetBlockchainHash(); try { var client = new RestClient(baseUrl); var request = new RestRequest("addblock", Method.POST); //request.AddParameter("TenantID", AbpSession.TenantId, ParameterType.HttpHeader); request.AddParameter("TenantID", "0", ParameterType.HttpHeader); request.AddParameter("UserID", "0", ParameterType.HttpHeader); request.AddParameter("UpdatedByUserID", input.UpdatedByUserId, ParameterType.HttpHeader); request.AddParameter("RequestingUserID", input.UserID, ParameterType.HttpHeader); request.AddParameter("LedgerName", input.LedgerName, ParameterType.HttpHeader); request.AddParameter("IsFile", input.IsFile, ParameterType.HttpHeader); request.AddParameter("FileExtension", input.FileExtension, ParameterType.HttpHeader); request.AddParameter("SaveTextAsFile", input.SaveTextAsFile, ParameterType.HttpHeader); request.AddParameter("IsSmartContract", input.IsSmartContract, ParameterType.HttpHeader); request.AddParameter("BlockName", input.BlockName, ParameterType.HttpHeader); //request.AddParameter("BlockName", "ATLANTA9990000000001", ParameterType.HttpHeader); request.AddParameter("BlockDescription", input.BlockDescription, ParameterType.HttpHeader); request.AddParameter("BlockProofHash", input.BlockProofHash, ParameterType.HttpHeader); if (hash != null) { request.AddParameter("BlockchainProofHash", hash, ParameterType.HttpHeader); } else { request.AddParameter("BlockchainProofHash", input.BlockchainProofHash, ParameterType.HttpHeader); } request.AddParameter("IsActive", input.IsActive, ParameterType.HttpHeader); request.AddParameter("BPAASToken", token, ParameterType.HttpHeader); request.AddParameter("BPAASRoles", string.Empty, ParameterType.HttpHeader); //format json to match with bpaas service format to allow querying //string formattedJson1 = input.Body.Replace("\"", "\\u022"); //input.Body.Replace('"', '\''); //formattedJson1 = "{"BpaaSPayload":" + formattedJson1 + "}"; dynamic body = JsonConvert.DeserializeObject <dynamic>(input.Body); BpaasPayload payload = new BpaasPayload(body); string formattedBody = JsonConvert.SerializeObject(payload); //string formattedJson = formattedBody.Replace("\\", "");//.Replace("\"", "\\u022"); request.AddParameter("body", formattedBody, ParameterType.RequestBody); IRestResponse response = await client.ExecuteAsync(request); if (response != null) { var tempresult = JsonConvert.DeserializeObject <dynamic>(response.Content); if (response.StatusCode == System.Net.HttpStatusCode.OK) { try { result = JsonConvert.DeserializeObject <AddBlockResponse>(tempresult); } catch (Exception ex) { result.message = "Fail to deserilaized the response"; } result.success = true; result.message = result.statusMessage; } else { result.success = false; try { AddBlockResponse temp = JsonConvert.DeserializeObject <AddBlockResponse>(tempresult); result.message = CleanUpErrroMessage(temp.statusMessage); } catch (Exception ex) { result.message = CleanUpErrroMessage(tempresult); } } } else { result.success = false; result.message = "BPaaS Service retunred null response"; } } catch (Exception e) { Console.WriteLine("{0} Exception caught.", e); result.success = false; result.message = e.Message; } return(result); }