protected void btnAddToRequest_Click(object sender, EventArgs e) { if (Page.IsValid) { //add item from existing database if (Request.QueryString["REQUESTCODE"] != null) { if ((string)Request.QueryString["REQUESTCODE"] != "") { RequestDetail requestDetail = null; if (!String.IsNullOrEmpty(tbxQuantity.Text)) { requestDetail = new RequestDetail(); requestDetail.RequestCode = (string)Request.QueryString["REQUESTCODE"]; requestDetail.ItemCode = (string)Request.QueryString["ItemCode"]; requestDetail.Quantity = requestDetail.RemainingQuant = Convert.ToInt32(tbxQuantity.Text); //newItem = new RequestDTO(lblItemCode.Text, lblCategory.Text, lblDescription.Text, Convert.ToInt32(tbxQuantity.Text)); //addItem.Add(newItem); //Session["ItemDetails"] = addItem; } else if (rdlQuantity.SelectedItem.Selected) { requestDetail = new RequestDetail(); requestDetail.RequestCode = (string)Request.QueryString["REQUESTCODE"]; requestDetail.ItemCode = (string)Request.QueryString["ItemCode"]; requestDetail.Quantity = requestDetail.RemainingQuant = Convert.ToInt32(rdlQuantity.SelectedItem.Text); //newItem = new RequestDTO(lblItemCode.Text, lblCategory.Text, lblCategory.Text, Convert.ToInt32(rdlQuantity.SelectedItem.Text)); //addItem.Add(newItem); //Session["ItemDetails"] = addItem; } if (requestDetail != null) { RequestDetail existingRequestDetail = ec.GetRequestDetail(requestDetail.RequestCode, requestDetail.ItemCode); if (existingRequestDetail == null) { ec.AddRequestDetail(requestDetail); } else { existingRequestDetail.Quantity += requestDetail.Quantity; existingRequestDetail.RemainingQuant += requestDetail.RemainingQuant; ec.UpdateRequestDetail(existingRequestDetail); } } } } else { //add item to new request List <RequestDTO> addItem = (List <RequestDTO>)Session["ItemDetails"]; RequestDTO newItem = addItem.FirstOrDefault(x => x.ItemCode == lblItemCode.Text); if (newItem == null) { if (!String.IsNullOrEmpty(tbxQuantity.Text)) { newItem = new RequestDTO(lblItemCode.Text, lblCategory.Text, lblDescription.Text, Convert.ToInt32(tbxQuantity.Text)); addItem.Add(newItem); Session["ItemDetails"] = addItem; } else if (rdlQuantity.SelectedItem.Selected) { newItem = new RequestDTO(lblItemCode.Text, lblCategory.Text, lblCategory.Text, Convert.ToInt32(rdlQuantity.SelectedItem.Text)); addItem.Add(newItem); Session["ItemDetails"] = addItem; } } else { if (!String.IsNullOrEmpty(tbxQuantity.Text)) { newItem.Quantity += Convert.ToInt32(tbxQuantity.Text); addItem.RemoveAll(x => x.ItemCode == lblItemCode.Text); addItem.Add(newItem); Session["ItemDetails"] = addItem; } else if (rdlQuantity.SelectedItem.Selected) { newItem.Quantity += Convert.ToInt32(rdlQuantity.SelectedItem.Text); addItem.RemoveAll(x => x.ItemCode == lblItemCode.Text); addItem.Add(newItem); Session["ItemDetails"] = addItem; } } } if (IsRedirect() && Session["ItemDetails"] != null) { Response.Redirect("RequisitionDetails.aspx?REQUESTCODE=" + requestcode); } else { //show success message System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append(@"<script type='text/javascript'>"); sb.Append("$('#myModal').modal('show');"); sb.Append(@"</script>"); ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "none", sb.ToString(), false); } } }