public async Task <HttpResponseMessage> GetApiCallForPreferences(SearchCriteria <string> searchCeiteria) { //string workbook, List<string> preferenceList WorkbookManager manager = new WorkbookManager(); try { Dictionary <string, List <string> > apiList = await manager.GetPreferencesForApiCall(searchCeiteria.Workbook, searchCeiteria.SearchList); ApiInfoBasedOnWbResponse response = new ApiInfoBasedOnWbResponse { IsError = false }; if (apiList.Count > 0) { foreach (string api in apiList.Keys) { WbInfoBasedOnApiCall info = new WbInfoBasedOnApiCall(); List <Preference> preferences = new List <Preference>(); foreach (string preference in apiList[api]) { preferences.Add(new Preference { PreferenceName = preference }); } info.WbPreferences = preferences; info.Workbook = searchCeiteria.Workbook; info.Api = api; response.Content.Add(info); } response.StatusCode = HttpStatusCode.OK; } return(Request.CreateResponse <ApiInfoBasedOnWbResponse>(HttpStatusCode.OK, response)); } catch (Exception ex) { var errorResponse = new ErrorResponse { IsError = true, StatusCode = HttpStatusCode.InternalServerError, Content = new List <Error>() { { new Error { Message = ex.Message, Workbook = searchCeiteria.Workbook } } } }; return(Request.CreateResponse <ErrorResponse>(HttpStatusCode.InternalServerError, errorResponse)); } }
public async Task <ActionResult> SearchApi(SearchCriteria <string> apis) { if (apis != null) { string urlendpoint = ""; Dictionary <string, string> content = new Dictionary <string, string>(); content.Add("Workbook", apis.Workbook); urlendpoint = "wbinfo/apis"; //if (apis.SearchOn == "apicall") // urlendpoint = "callinfo/apicall"; //else // urlendpoint = "callinfo/preferences"; for (int i = 0; i < apis.SearchList.Count; i++) { string key = string.Format($"SearchList[{i}]"); content.Add(key, apis.SearchList[i]); } WebHelper helper = new WebHelper(getUrl()); HttpResponseMessage responseMessage = await helper.CallService(IsWebApiCall : true , urlEndpoint : urlendpoint , method : HttpMethod.Post , contentToPassToServer : content); if (responseMessage.IsSuccessStatusCode) { var responseData = responseMessage.Content.ReadAsStringAsync().Result; JsonSerializerSettings settings = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Include }; var workbookInfo = JsonConvert.DeserializeObject <WbInfoBasedOnApiCallResponse>(responseData, settings); WbInfoBasedOnApiCall info = new WbInfoBasedOnApiCall(); if (workbookInfo.Content.Count > 0) { info = workbookInfo.Content[0]; } ModelState.Clear(); return(View(info)); } else { ParameterError(responseMessage.Content.ReadAsStringAsync().Result); } } return(ParameterError()); }