//Add new record protected void Add_Click(object sender, EventArgs e) { LEAVEALLOCATION new_leaveallocation = new LEAVEALLOCATION(); //get job title id foreach (var jobtitle in jobtitles) { if (DropDownList1.SelectedValue.Equals(jobtitle.JobTitleName)) { new_leaveallocation.JobTitleId = jobtitle.JobTitleId; break; } } //get leave type id foreach (var leavetype in leavetypes) { if (DropDownList2.SelectedValue.Equals(leavetype.LeaveTypeName)) { new_leaveallocation.LeaveTypeId = leavetype.LeaveTypeId; break; } } new_leaveallocation.NumberOfLeave = Convert.ToInt32(DaysTextBox.Text); using (var client = new HttpClient()) { client.BaseAddress = new Uri(Global.URIstring); var postTask = client.PostAsJsonAsync("LeaveAllocation", new_leaveallocation); postTask.Wait(); var result = postTask.Result; if (result.IsSuccessStatusCode) { DaysTextBox.Text = null; DropDownList1.SelectedIndex = 0; DropDownList2.SelectedIndex = 0; } } DropDownList3.SelectedIndex = 0; DropDownList4.SelectedIndex = 0; loadleaveallocation(); filterdata(); //gvbind(); }
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { GridViewRow row = (GridViewRow)GridView1.Rows[e.RowIndex]; TextBox leavedays = row.Cells[3].Controls[0] as TextBox; string title = row.Cells[1].Text; string type = row.Cells[2].Text; LEAVEALLOCATION leaveallocation = new LEAVEALLOCATION(); GridView1.EditIndex = -1; using (var client = new HttpClient()) { string titleid = null, typeid = null; //assign new value to leave allocation oject foreach (var jobtitle in jobtitles) { if (jobtitle.JobTitleName.Equals(title)) { leaveallocation.JobTitleId = jobtitle.JobTitleId; titleid = jobtitle.JobTitleId.ToString(); } } foreach (var leavetype in leavetypes) { if (leavetype.LeaveTypeName.Equals(type)) { leaveallocation.LeaveTypeId = leavetype.LeaveTypeId; typeid = leavetype.LeaveTypeId.ToString(); } } leaveallocation.NumberOfLeave = Convert.ToInt32(leavedays.Text); client.BaseAddress = new Uri(Global.URIstring); //HTTP PUT string str = "LeaveAllocation?jobtitleid=" + titleid + "&leavetypeid=" + typeid; var updateTask = client.PutAsJsonAsync(str, leaveallocation); updateTask.Wait(); var result = updateTask.Result; } loadleaveallocation(); filterdata(); // gvbind(); }