static DataTable SaveMessage2DBAndSelect(int id_user_from, int id_user_to, string message, string gift_list, int id_offer) { DB_Helper db = new DB_Helper(); string s = ""; if (MyUtils.IsFemale) { s = "select female_sent_msg from offers where id_offer=" + id_offer; int female_sent_msg = db.ExecuteScalarIntCache(s, 0, 5); if (female_sent_msg == 0) { db.Execute("update offers set female_sent_msg=1 where isnull(female_sent_msg,0)=0 and id_offer=" + id_offer + "; "); DB_Helper.InvalidateCache("SQL_" + s); } } return(db.GetDataSet("insert into messages (id_user_from,id_user_to,text,gift_list,id_offer) OUTPUT inserted.* values (" + id_user_from + "," + id_user_to + "," + MyUtils.safe(message) + "," + MyUtils.safe(gift_list) + "," + id_offer + ");").Tables[0]); }
public static Message SendMessage(string message, string toUser, string giftIds) { DB_Helper db = new DB_Helper(); var fromUser = MyUtils.ID_USER; message = MyUtils.StripHTML(message); giftIds = MyUtils.StripHTML(giftIds); int id_user_to = Convert.ToInt32(toUser); int id_offer = db.ExecuteScalarInt("exec CAN_MESSAGE_WITH " + Convert.ToInt32(fromUser) + "," + id_user_to, 0); if (id_offer == 0) { Message mm = new Message(); mm.Text = "You don't have permission to send messages to this user."; return(mm); } if (message.Trim() == "") { return(null); } if (!string.IsNullOrEmpty(giftIds)) { Gifts g = new Gifts(giftIds); string err = g.AddGifts2User(MyUtils.ID_USER, id_user_to); if (err != "") { Message mmm = new Message(); mmm.Text = err; return(mmm); } } var table = SaveMessage2DBAndSelect(fromUser, id_user_to, message, giftIds, id_offer); //make sure we don't send too many notification emails int unread_messages_in_10_mins = db.ExecuteScalarInt("select count(*) from Messages where id_user_from=" + fromUser + " and id_user_to=" + id_user_to + " and is_new = 1 and [time] > DATEADD(minute, -10, GETDATE())"); if (unread_messages_in_10_mins < 2) { RWorker.AddToEmailQueue("EMAIL_NEWMESSAGE", id_user_to, MyUtils.ID_USER); } DB_Helper.InvalidateCache("TOPCOUNTS_" + MyUtils.ID_USER); DB_Helper.InvalidateCache("TOPCOUNTS_" + id_user_to); var query = from p in table.AsEnumerable() select new Message { Id = p.Field <int>("id_message"), Text = p.Field <string>("text"), From = new User { Name = "You", Id = p.Field <int>("id_user_from") }, To = new User { Name = "Female123", //TODO Id = p.Field <int>("id_user_from") }, DateTime = p.Field <DateTime>("time"), IsFromMe = true }; Message m = query.First(); if (!string.IsNullOrEmpty(giftIds)) { m.Credits = Convert.ToInt32(MyUtils.GetUserField("credits")); } return(m); }