public ActionResult Update(ProjectJobTypesModel cm) { try { List <ProjectJobTypesModel> ProjectJobTypesInfo = new List <ProjectJobTypesModel>(); using (var client = new HttpClient()) { client.BaseAddress = new Uri(Baseurl); //HTTP GET var responseTask = client.PutAsJsonAsync("api/ProjectJobTypes/update", cm); responseTask.Wait(); var result = responseTask.Result; if (result.IsSuccessStatusCode) { //Storing the response details recieved from web api var ProjectJobTypesResponse = result.Content.ReadAsStringAsync().Result; //Deserializing the response recieved from web api and storing into the Sub SORType list ProjectJobTypesInfo = JsonConvert.DeserializeObject <List <ProjectJobTypesModel> >(ProjectJobTypesResponse); } } return(RedirectToAction("Index", "Project")); } catch (Exception ex) { ExceptionLogHandler.LogData(ex); throw ex; } }
public async Task <ActionResult> Insert(ProjectJobTypesModel projJobTypes) { try { ProjectJobTypesModel ProjectJobTypesInfo = new ProjectJobTypesModel(); using (var client = new HttpClient()) { //Passing service base url client.BaseAddress = new Uri(Baseurl); client.DefaultRequestHeaders.Clear(); var obj = JsonConvert.SerializeObject(projJobTypes); // Define request data format client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); //Sending request to find web api REST service resource GetAllComapnies using HttpClient HttpResponseMessage Res = await client.PostAsync("api/ProjectJobTypes/insert", new StringContent(obj, Encoding.UTF8, "application/json")); //Checking the response is successful or not which is sent using HttpClient if (Res.IsSuccessStatusCode) { //Storing the response details recieved from web api var ProjectJobTypesResponse = Res.Content.ReadAsStringAsync().Result; //Deserializing the response recieved from web api and storing into the Company list ProjectJobTypesInfo = JsonConvert.DeserializeObject <ProjectJobTypesModel>(ProjectJobTypesResponse); } //returning the company list to view } return(RedirectToAction("Index", "Project")); } catch (Exception ex) { ExceptionLogHandler.LogData(ex); throw ex; } }