I have a webmethod insert that i want to add delete, if user insert if the user clicks same button it deletes the post.
Am trying to add delete on this example link below the user insert from the modal is ok but i need to add delete to avoid dublicate entry
see link
https://www.aspforums.net/Threads/178177/Change-ASPNet-DataList-selected-Label-font-icon-based-on-Bootstrap-Modal-icon-selection-using-jQuery-AJAX/
then i tried to add the delete code but i dont know how to fix that
//LIKEBUTTON HERE
[WebMethod]
public static string INSERTUSERSTATUS(string userName, string icon, string postId)
{
string constr = ConfigurationManager.ConnectionStrings["DB"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("INSERT INTO [UserPICKS](UserName,statuscount,Iconbook,IconCup,IconPen,PostId6) VALUES(@UserName,@statuscount,@Iconbook,@IconCup,@IconPen,@PostId6)"))
{
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@UserName", HttpContext.Current.Session["userName"]);
cmd.Parameters.AddWithValue("@statuscount", "1");
if (icon.ToLower() == "fa fa-book")
{
cmd.Parameters.AddWithValue("@Iconbook", "book");
cmd.Parameters.AddWithValue("@IconCup", "");
cmd.Parameters.AddWithValue("@IconPen", "");
}
if (icon.ToLower() == "fa fa-coffee")
{
cmd.Parameters.AddWithValue("@Iconbook", "");
cmd.Parameters.AddWithValue("@IconCup", "cup");
cmd.Parameters.AddWithValue("@IconPen", "");
}
if (icon.ToLower() == "fa fa-pencil")
{
cmd.Parameters.AddWithValue("@Iconbook", "");
cmd.Parameters.AddWithValue("@IconCup", "");
cmd.Parameters.AddWithValue("@IconPen", "pen");
}
cmd.Parameters.AddWithValue("@PostId6", postId);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
return "posted";
}
}
else
{
using (SqlCommand cmd = new SqlCommand("DELETE FROM UserPICKS WHERE UserName = @UserName AND PostId = @PostId", con))
{
cmd.Parameters.AddWithValue("@PostId", postId);
cmd.Parameters.AddWithValue("@UserName", HttpContext.Current.Session["userName"].ToString());
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
}
return values;
}