private void FetchRecords() { using (var client = new HttpClient()) { client.BaseAddress = new Uri(System.Configuration.ConfigurationManager.AppSettings["uri"]); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); string api = "api/ItemStatuses/" + _PKey; var response = client.GetAsync(api).Result; if (response.IsSuccessStatusCode) { var a = response.Content.ReadAsStringAsync().Result; ItemStatusUpdate itemStatusUpdates = JsonConvert.DeserializeObject <ItemStatusUpdate>(a); txtCode_ItemStatus.Value = itemStatusUpdates.statusCode; ddlGroup_ItemStatus.Value = itemStatusUpdates.statusGroupCode; txteDesc_ItemStatus.Value = itemStatusUpdates.statusDesc; txtShortDesc_ItemStatus.Value = itemStatusUpdates.statusShortDesc; chkStatusActive_ItemStatus.Checked = itemStatusUpdates.itmIsactive; } else { Console.WriteLine("Internal server Error"); } } }
protected void Operation_Click(object sender, EventArgs e) { try { if (Validation()) { if (btn_AddItemStatus.InnerText.Trim() == "Add") { using (var client = new HttpClient()) { ItemStatus p = new ItemStatus { statusCode = txtCode_ItemStatus.Value.ToString().Trim(), statusDesc = txteDesc_ItemStatus.Value.ToString().Trim(), statusShortDesc = txtShortDesc_ItemStatus.Value.ToString().Trim(), statusGroupCode = ddlGroup_ItemStatus.Value.ToString().Trim(), itmIsactive = chkStatusActive_ItemStatus.Checked }; client.BaseAddress = new Uri(System.Configuration.ConfigurationManager.AppSettings["uri"]); client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); var post = client.PostAsJsonAsync <ItemStatus>("api/ItemStatuses", p); post.Wait(); var response = post.Result; if (response.IsSuccessStatusCode) { ControlNosUpdate c = new ControlNosUpdate { controldescription = "Item Status Code", sitecode = System.Configuration.ConfigurationManager.AppSettings["SiteCode"].ToString(), controlnumber = Convert.ToString((Int64.Parse(Session["ControlNo"].ToString()) + 1)) }; string api = "api/ControlNos/updatecontrol"; post = client.PostAsJsonAsync <ControlNosUpdate>(api, c); post.Wait(); response = post.Result; if (response.IsSuccessStatusCode) { txtCode_ItemStatus.Value = Session["Prefix"].ToString() + Convert.ToString((Int64.Parse(Session["ControlNo"].ToString()) + 1)); } oCommonEngine.SetAlert(this.Page, "Item Status Saved Successfully..!", Utilities.CommonEngine.MessageType.Success, Utilities.CommonEngine.MessageDuration.Short); } else { oCommonEngine.SetAlert(this.Page, response.StatusCode + "...!", Utilities.CommonEngine.MessageType.Error, Utilities.CommonEngine.MessageDuration.Short); } } } else { using (var client = new HttpClient()) { ItemStatusUpdate p = new ItemStatusUpdate { itmId = Int32.Parse(_PKey), statusCode = txtCode_ItemStatus.Value.ToString().Trim(), statusDesc = txteDesc_ItemStatus.Value.ToString().Trim(), statusShortDesc = txtShortDesc_ItemStatus.Value.ToString().Trim(), statusGroupCode = ddlGroup_ItemStatus.Value.ToString().Trim(), itmIsactive = chkStatusActive_ItemStatus.Checked }; client.BaseAddress = new Uri(System.Configuration.ConfigurationManager.AppSettings["uri"]); client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); var post = client.PutAsJsonAsync <ItemStatusUpdate>("api/ItemStatuses", p); post.Wait(); var response = post.Result; if (response.IsSuccessStatusCode) { oCommonEngine.SetAlert(this.Page, "Item Status Updated Successfully..!", Utilities.CommonEngine.MessageType.Success, Utilities.CommonEngine.MessageDuration.Short); } else { oCommonEngine.SetAlert(this.Page, response.StatusCode + "...!", Utilities.CommonEngine.MessageType.Error, Utilities.CommonEngine.MessageDuration.Short); } CollapsiblePanelItemStatusList.Collapsed = false; Get_ControlPrefixs(); } Get_ControlPrefixs(); } DataClear(); Get_ItemStatus(); } } catch (Exception Ex) { oCommonEngine.SetAlert(this.Page, Ex.Message, Utilities.CommonEngine.MessageType.Error, Utilities.CommonEngine.MessageDuration.Short); } }