Exemple #1
0
        public ActionResult Update(JobDefectsModel cm)
        {
            try
            {
                List <JobDefectsModel> JobDefectsInfo = new List <JobDefectsModel>();
                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri(Baseurl);
                    //HTTP GET
                    var responseTask = client.PutAsJsonAsync("api/JobDefects/update", cm);
                    responseTask.Wait();

                    var result = responseTask.Result;
                    if (result.IsSuccessStatusCode)
                    {
                        //Storing the response details recieved from web api
                        var JobDefectsResponse = result.Content.ReadAsStringAsync().Result;

                        //Deserializing the response recieved from web api and storing into the Sub SORType  list
                        JobDefectsInfo = JsonConvert.DeserializeObject <List <JobDefectsModel> >(JobDefectsResponse);
                    }
                }

                return(RedirectToAction("Index", "Jobs"));
            }
            catch (Exception ex)
            {
                ExceptionLogHandler.LogData(ex);

                throw ex;
            }
        }
Exemple #2
0
        public async Task <ActionResult> Insert(JobDefectsModel cm)
        {
            try
            {
                JobDefectsModel JobDefectsInfo = new JobDefectsModel();
                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/JobDefects/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 JobDefectsResponse = Res.Content.ReadAsStringAsync().Result;

                        //Deserializing the response recieved from web api and storing into the Company list
                        JobDefectsInfo = JsonConvert.DeserializeObject <JobDefectsModel>(JobDefectsResponse);
                    }

                    //returning the company list to view
                    return(RedirectToAction("Index", "Jobs"));
                }
            }
            catch (Exception ex)
            {
                ExceptionLogHandler.LogData(ex);

                throw ex;
            }
        }