private bool DeleteSingleMessageByMessageID(MessageSticker Message) { SqlConnection con = null; try { con = new SqlConnection(WebConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString); string delete = "DELETE FROM MessageSticker WHERE MessageID=@MessageID"; SqlCommand command = new SqlCommand(delete, con); command.Parameters.AddWithValue("@MessageID", Message.MessageID); con.Open(); command.ExecuteNonQuery(); return(true); } catch (Exception err) { StatusMessage.Text = "Грешка, обидете се повторно (11) " + err.Message; } finally { if (con != null) { con.Close(); } } return(false); }
private bool SenderIsBuying(MessageSticker Message) { SqlConnection con = null; try { string ThisUserID = MessageSticker.PosterUserID; string SenderUserID = Message.SenderUserID; con = new SqlConnection(WebConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString); //get cash string select = "SELECT Cash,UserId FROM aspnet_Users WHERE UserId=@PosterID OR UserId=@SenderID"; SqlCommand command = new SqlCommand(select, con); command.Parameters.AddWithValue("@PosterID", ThisUserID); command.Parameters.AddWithValue("@SenderID", SenderUserID); con.Open(); SqlDataReader reader = command.ExecuteReader(); int ThisUserCash = 0; int SenderCash = 0; while (reader.Read()) { if (reader["UserId"].ToString() == ThisUserID) { ThisUserCash = (int)reader["Cash"]; } else if (reader["UserId"].ToString() == SenderUserID) { SenderCash = (int)reader["Cash"]; } } reader.Close(); ThisUserCash += Message.Offer; SenderCash -= Message.Offer; //update cash string update = "UPDATE aspnet_Users SET Cash=@Cash WHERE UserId=@Userid"; command.CommandText = update; command.Parameters.Clear(); command.Parameters.AddWithValue("@Cash", ThisUserCash); command.Parameters.AddWithValue("@Userid", ThisUserID); command.ExecuteNonQuery(); command.Parameters.Clear(); command.Parameters.AddWithValue("@Cash", SenderCash); command.Parameters.AddWithValue("@Userid", SenderUserID); command.ExecuteNonQuery(); //transfer sticker to sender update = "UPDATE Sticker SET UserID=@SenderID WHERE StickerID=@StickerID"; command.CommandText = update; command.Parameters.Clear(); command.Parameters.AddWithValue("@SenderID", SenderUserID); command.Parameters.AddWithValue("@StickerID", Message.PosterStickerID); command.ExecuteNonQuery(); //transfer sticker to poster if sender offered one if (!string.IsNullOrWhiteSpace(Message.SenderStickerID)) { update = "UPDATE Sticker SET UserID=@ThisUserID WHERE StickerID=@StickerID"; command.CommandText = update; command.Parameters.Clear(); command.Parameters.AddWithValue("@ThisUserID", ThisUserID); command.Parameters.AddWithValue("@StickerID", Message.SenderStickerID); command.ExecuteNonQuery(); } //delete post from PostSticker string delete = "DELETE FROM PostSticker WHERE StickerID=@PosterStickerID AND PosterID=@PosterID"; command.CommandText = delete; command.Parameters.Clear(); command.Parameters.AddWithValue("@PosterStickerID", Message.PosterStickerID); command.Parameters.AddWithValue("@PosterID", ThisUserID); command.ExecuteNonQuery(); return(true); } catch (Exception err) { StatusMessage.Text = "Грешка, обидете се повторно (12345) " + err.Message; } finally { if (con != null) { con.Close(); } } return(false); }