public ActionResult Update(JobDocumentsModel cm) { try { List <JobDocumentsModel> JobDocumentsInfo = new List <JobDocumentsModel>(); using (var client = new HttpClient()) { client.BaseAddress = new Uri(Baseurl); //HTTP GET var responseTask = client.PutAsJsonAsync("api/JobDocuments/update", cm); responseTask.Wait(); var result = responseTask.Result; if (result.IsSuccessStatusCode) { //Storing the response details recieved from web api var JobDocumentsResponse = result.Content.ReadAsStringAsync().Result; //Deserializing the response recieved from web api and storing into the Sub SORType list JobDocumentsInfo = JsonConvert.DeserializeObject <List <JobDocumentsModel> >(JobDocumentsResponse); } } return(RedirectToAction("Index", "Jobs")); } catch (Exception ex) { ExceptionLogHandler.LogData(ex); throw ex; } }
public ActionResult JobDocuments(int JobId) { JobDocumentsModel _JobDocumentsModel = new JobDocumentsModel(); List <JobDocuments> _JobDocumentsList = _JobDocumentsModel.GetList(" * ", "JobId = " + JobId); if (_JobDocumentsList.Count() > 0) { return(Json(_JobDocumentsList, JsonRequestBehavior.AllowGet)); } else { return(Json("Falied", JsonRequestBehavior.AllowGet)); } }
public async Task <ActionResult> Insert(JobDocumentsModel cm) { try { JobDocumentsModel JobDocumentsInfo = new JobDocumentsModel(); using (var client = new HttpClient()) { //Passing service base url client.BaseAddress = new Uri(Baseurl); client.DefaultRequestHeaders.Clear(); var obj = JsonConvert.SerializeObject(cm); // 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/JobDocuments/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 JobDocumentsResponse = Res.Content.ReadAsStringAsync().Result; //Deserializing the response recieved from web api and storing into the Company list JobDocumentsInfo = JsonConvert.DeserializeObject <JobDocumentsModel>(JobDocumentsResponse); } //returning the company list to view return(RedirectToAction("Index", "Jobs")); } } catch (Exception ex) { ExceptionLogHandler.LogData(ex); throw ex; } }