protected void btnUpdate_Click(object sender, EventArgs e) { try { // labelMessage.Text = string.Empty; using (CategoryRT receiverTransfer = new CategoryRT()) { List <Category> categorieList = new List <Category>(); categorieList = receiverTransfer.GetCategoryByName(txtName.Text); bool IsParentIdSame = false; foreach (var cat in categorieList) { if (cat.ParentID == Convert.ToInt32(txtParentID.Text)) { IsParentIdSame = true; } } if (IsParentIdSame) { string msg = "Category Name " + txtName.Text + " Already Exists in this parent category!"; //string alertScript = //String.Format("alert('{0}');", msg); //Page.ClientScript.RegisterStartupScript(this.GetType(), "Key", alertScript, true); labelMessage.Text = msg; return; } hdIsEdit.Value = "true"; Category category = CreateCategory(); if (category != null) { receiverTransfer.UpdateCategory(category); labelMessage.Text = "Data successfully updated..."; labelMessage.ForeColor = System.Drawing.Color.Green; } else { labelMessage.Text = "Data not updated..."; labelMessage.ForeColor = System.Drawing.Color.Red; } } ClearField(); LoadCategory(); } catch (Exception ex) { labelMessage.Text = "Error : " + ex.Message; labelMessage.ForeColor = System.Drawing.Color.Red; } }
protected void btnDelete_Click(object sender, EventArgs e) { try { // labelMessage.Text = string.Empty; using (CategoryRT receiverTransfer = new CategoryRT()) { List <Category> catagory = new List <Category>(); catagory = receiverTransfer.GetAllCategoryByParentID(Convert.ToInt32(hdCategoryID.Value.ToString())); if (catagory.Count == 0) { hdIsDelete.Value = "true"; hdIsEdit.Value = "true"; Category category = CreateCategory(); if (category != null) { receiverTransfer.UpdateCategory(category); labelMessage.Text = "Data successfully deleted..."; labelMessage.ForeColor = System.Drawing.Color.Green; } else { labelMessage.Text = "Data not deleted..."; labelMessage.ForeColor = System.Drawing.Color.Red; } } else { labelMessage.Text = "Data not deleted. Please Delete the sub category frist....."; labelMessage.ForeColor = System.Drawing.Color.Red; } } LoadCategory(); ClearField(); } catch (Exception ex) { labelMessage.Text = "Error : " + ex.Message; labelMessage.ForeColor = System.Drawing.Color.Red; } }