public async Task <ProjectApprovedBudget> GetProjectApprovedBudgetAsync(string projectID, string user) //Rename this { using (var client = new HttpClient()) { client.BaseAddress = new Uri(AMPUtilities.FinanceWebServiceUrl()); // We should store this in the web.config file client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); // This probably removes the need to have the config in the API try { // HTTP GET HttpResponseMessage response = await client.GetAsync("Projects/ProjectApprovedBudgets/" + projectID);// This URI shouldbe in the web.config file or passed via the AMP Service Layer. if (response.IsSuccessStatusCode) { ProjectApprovedBudget projectApprovedBudget = Newtonsoft.Json.JsonConvert.DeserializeObject <ProjectApprovedBudget>(response.Content.ReadAsStringAsync().Result); return(projectApprovedBudget); } else { Exception ex = new Exception(response.StatusCode.ToString() + " - " + response.ReasonPhrase.ToString()); // Executes the error engine (ProjectID is optional, exception) errorengine.LogError(projectID, ex, user); throw ex; } } catch (Exception ex) { // Executes the error engine (ProjectID is optional, exception) errorengine.LogError(projectID, ex, user); throw ex; } } }
public async Task <IEnumerable <SupplierVM> > GetSearchSuppliers(IEnumerable <String> searchString, string user) { using (var client = new HttpClient()) { client.BaseAddress = new Uri(AMPUtilities.FinanceWebServiceUrl()); // We should store this in the web.config file client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); // This probably removes the need to have the config in the API try { // string logonName = empNo.Substring(5); string queryString = BuildQueryStringFromList(searchString.ToList()); // HTTP GET HttpResponseMessage response = await client.GetAsync("API/ProjectAPI/GetSearchSuppliers/?" + queryString);// This URI shouldbe in the web.config file or passed via the AMP Service Layer. if (response.IsSuccessStatusCode) { IEnumerable <SupplierVM> suppliers = JsonConvert.DeserializeObject <IEnumerable <SupplierVM> >(response.Content.ReadAsStringAsync().Result); return(suppliers); } else if (response.StatusCode == HttpStatusCode.NotFound) { //This user has no projects to get budgets for. return(null); } else { Exception ex = new Exception(response.StatusCode.ToString() + " - " + response.ReasonPhrase.ToString()); // Executes the error engine (ProjectID is optional, exception) errorengine.LogError(ex, user); throw ex; } } catch (Exception ex) { // Executes the error engine (ProjectID is optional, exception) errorengine.LogError(ex, user); throw ex; } } }