Пример #1
0
        protected void btnSend_Click(object sender, EventArgs e)
        {
            EcardType ecardType = EcardType.Fetch(Convert.ToInt32(ddEcards.SelectedValue));

            if (ecardType != null)
            {
                //var permissionResult = CurrentUserSession.CanSendEcards();

                if (canSendEcardPermissionResult == PermissionCheckResult.No)
                {
                    StatusPageMessage = "You are not allowed to send e-cards".Translate();
                    Response.Redirect("ShowStatus.aspx");
                    return;
                }

                if (canSendEcardPermissionResult == PermissionCheckResult.YesButMoreCreditsNeeded ||
                    canSendEcardPermissionResult == PermissionCheckResult.YesButPlanUpgradeNeeded)
                {
                    Session["BillingPlanOption"] = CurrentUserSession.BillingPlanOptions.CanSendEcards;
                    Response.Redirect("ManageProfile.aspx?sel=payment");
                    return;
                }

                if (canSendEcardPermissionResult == PermissionCheckResult.YesWithCredits)
                {
                //if (Config.Credits.Required && CurrentUserSession.BillingPlanOptions.CanSendEcards.Credits > 0)
                //{
                //    if (!Config.Users.FreeForFemales ||
                //        CurrentUserSession.Gender != Classes.User.eGender.Female)
                //    {
                    int creditsCost = CurrentUserSession.BillingPlanOptions.CanSendEcards.Credits;
                    int creditsLeft = CurrentUserSession.Credits - creditsCost;

                    if (!Config.Credits.ChargeOneTimePerMember) // charge every time
                    {
                        if (creditsLeft < 0)
                        {
                            Session["BillingPlanOption"] = CurrentUserSession.BillingPlanOptions.CanSendEcards;
                            Response.Redirect("~/ManageProfile.aspx?sel=payment");
                            return;
                        }

                        var user = Classes.User.Load(CurrentUserSession.Username);
                        user.Credits -= creditsCost;
                        user.Update(true);
                        CurrentUserSession.Credits = user.Credits;
                    }
                    else
                    {
                        bool isCharged = EstablishedCommunication.Fetch(CurrentUserSession.Username,
                            RecipientUsername) != null;

                        if (!isCharged)
                        {
                            if (creditsLeft >= 0)
                            {
                                var establishedCommunication =
                                    new EstablishedCommunication(CurrentUserSession.Username, RecipientUsername);

                                establishedCommunication.Save();

                                var user = Classes.User.Load(CurrentUserSession.Username);
                                user.Credits -= creditsCost;
                                user.Update(true);
                                CurrentUserSession.Credits = user.Credits;
                            }
                            else
                            {
                                Session["BillingPlanOption"] = CurrentUserSession.BillingPlanOptions.CanSendEcards;
                                Response.Redirect("~/ManageProfile.aspx?sel=payment");
                                return;
                            }
                        }
                    }
                //    }
                }

                Ecard ecard = new Ecard(ecardType.ID, CurrentUserSession.Username, RecipientUsername);
                string message = htmlEditor != null ? htmlEditor.Content : ckeditor.Text;
                ecard.Message = message.Trim();
                ecard.Save();

                User recipient = null;
                try
                {
                    recipient = Classes.User.Load(RecipientUsername);
                }
                catch (NotFoundException)
                {
                    StatusPageMessage = "The user no longer exists!".Translate();
                    Response.Redirect("~/ShowStatus.aspx");
                    return;
                }

                if (Classes.User.IsUserBlocked(RecipientUsername, CurrentUserSession.Username))
                {
                    StatusPageMessage =
                        String.Format(Lang.Trans("You are currently blocked from sending e-cards to {0}"),
                                      RecipientUsername);
                    Response.Redirect("ShowStatus.aspx");
                    return;
                }

                if (recipient.ReceiveEmails)
                {
                    EmailTemplates.SendEcard sendEcardTemplate = new EmailTemplates.SendEcard(recipient.LanguageId);

                    Email.Send(Config.Misc.SiteTitle, Config.Misc.SiteEmail, recipient.Name, recipient.Email,
                               sendEcardTemplate.GetFormattedSubject(CurrentUserSession.Username),
                               sendEcardTemplate.GetFormattedBody(CurrentUserSession.Username), false);
                }

                if (Config.Users.NewEventNotification)
                {
                    int imageID = 0;
                    try
                    {
                        imageID = Photo.GetPrimary(CurrentUserSession.Username).Id;
                    }
                    catch (NotFoundException)
                    {
                        imageID = ImageHandler.GetPhotoIdByGender(CurrentUserSession.Gender);
                    }
                    string text = "You have a new e-card!".Translate();

                    string thumbnailUrl = ImageHandler.CreateImageUrl(imageID, 50, 50, false, true, true);
                    Classes.User.SendOnlineEventNotification(CurrentUserSession.Username, recipient.Username, text,
                                                             thumbnailUrl, "Mailbox.aspx?sel=recec");
                }

                StatusPageLinkText = "Back to profile".Translate();
                StatusPageLinkURL = UrlRewrite.CreateShowUserUrl(RecipientUsername);
                StatusPageMessage = Lang.Trans("<b>Your e-card was sent successfully!</b><br><br>");
                Response.Redirect("~/ShowStatus.aspx");    
            }
        }
Пример #2
0
        protected void btnSend_Click(object sender, EventArgs e)
        {
            #region Check can current user send message

            Classes.User toUser = null;
            User fromUser = null;
            try
            {
                toUser = Classes.User.Load((string)ViewState["SendMessage_ToUsername"]);
                fromUser = Classes.User.Load(CurrentUserSession.Username);
            }
            catch (NotFoundException)
            {
                Response.Redirect(MatchmakerHelper.CurrentHomePage);
                return;
            }

            string reason;
            if (!Message.MessagesExist(toUser.Username, fromUser.Username) &&
                    !Classes.User.CanSendMessage(fromUser, toUser, out reason) && !CurrentUserSession.IsAdmin())
            {
                if (!Classes.User.IsGroupOwner(fromUser, toUser))
                {
                    StatusPageMessage = reason;
                    return;
                }
            }

            #endregion

            try
            {
                var toUsername = (string)ViewState["SendMessage_ToUsername"];

                if (Classes.User.IsUserBlocked(toUsername, CurrentUserSession.Username))
                {
                    StatusPageMessage =
                        String.Format(Lang.Trans("You are currently blocked from sending messages to {0}"), toUsername);
                    return;
                }

                var msg = new Message(CurrentUserSession.Username,
                                          toUsername)
                {
                    Body =
                        (Config.Misc.EnableBadWordsFilterMessage
                             ? Parsers.ProcessBadWords(txtMessageBody.Text.Trim())
                             : txtMessageBody.Text.Trim())
                };

                if (Config.Misc.EnableMessageFilter)
                {
                    msg.Body = ReplaceEmail(msg.Body, "***");
                    msg.Body = ReplacePhone(msg.Body, "***");
                }

                if (txtMessageBody.Text.Trim().Length == 0)
                {
                    return;
                }

                if (Request.Params["src"] != null && Request.Params["src"] == "message"
                    && Request.Params["src_id"] != null)
                {
                    try
                    {
                        msg.RepliedTo = Convert.ToInt32(Request.Params["src_id"]);
                    }
                    catch (InvalidCastException)
                    {
                    }
                }

                bool shouldPayWithCredits;
                checkMessagesLimitReached(out shouldPayWithCredits);

                if (shouldPayWithCredits)
                {
                    int creditsLeft = fromUser.Credits - CurrentUserSession.BillingPlanOptions.MaxMessagesPerDay.Credits; //Config.Credits.CreditsPerMessage;

                    if (!Config.Credits.ChargeOneTimePerMember) // charge every time
                    {
                        if (creditsLeft < 0)
                        {
                            StatusPageMessage = "You have to be paid memeber in order to use this feature!".Translate();
                            Response.Redirect("Home.aspx");
                            return;
                        }

                        fromUser.Credits -= CurrentUserSession.BillingPlanOptions.MaxMessagesPerDay.Credits;// Config.Credits.CreditsPerMessage;
                        fromUser.Update(true);
                        CurrentUserSession.Credits = fromUser.Credits;
                    }
                    else
                    {
                        bool isCharged = EstablishedCommunication.Fetch(fromUser.Username,
                            toUser.Username) != null;

                        if (!isCharged)
                        {
                            if (creditsLeft >= 0)
                            {
                                var establishedCommunication =
                                    new EstablishedCommunication(fromUser.Username, toUser.Username);

                                establishedCommunication.Save();

                                fromUser.Credits -= CurrentUserSession.BillingPlanOptions.MaxMessagesPerDay.Credits;
                                fromUser.Update(true);
                                CurrentUserSession.Credits = fromUser.Credits;
                            }
                            else
                            {
                                StatusPageMessage = "You have to be paid memeber in order to use this feature!".Translate();
                                Response.Redirect("Home.aspx");
                                return;
                            }
                        }
                    }
                }

                if (Config.Misc.EnableSpamDetection)
                {
                    if (fromUser.SpamSuspected)
                    {
                        StatusPageMessage =
                            Lang.Trans(
                                "This account is flagged for review! You will not be able to send messages untill the review is completed!");
                        return;
                    }

                    string message = Regex.Replace(msg.Body, @"[^\w]*", "").ToLower();

                    if (message.Length > 100)
                    {
                        message = message.Substring(0, 100);
                    }

                    int sentMessages = MessagesSandBox.Save(CurrentUserSession.Username, message);

                    if (sentMessages > Config.Misc.MaxSameMessages)
                    {
                        fromUser.SpamSuspected = true;
                        fromUser.Update();

                        StatusPageMessage =
                            Lang.Trans(
                                "This account is flagged for review! You will not be able to send messages untill the review is completed!");
                        return;
                    }
                }

                msg.Send();

                Classes.User.AddScore(toUsername, Config.UserScores.ReceivedMessage, "ReceivedMessage");
                if (msg.RepliedTo > 0)
                    Classes.User.AddScore(CurrentUserSession.Username, Config.UserScores.RepliedToMessage,
                        "RepliedToMessage");
                else
                    Classes.User.AddScore(CurrentUserSession.Username, Config.UserScores.SentMessage,
                        "SentMessage");

                StatusPageMessage = Lang.Trans
                    ("<b>Your message has been sent successfully!</b>");
            }
            catch (ThreadAbortException)
            {
            }
            catch (NotFoundException)
            {
                StatusPageMessage = Lang.Trans("The message could not be delivered because the target user was deleted");
            }
            catch (ArgumentException ex)
            {
                StatusPageMessage = ex.Message;
            }
            catch (Exception err)
            {
                StatusPageMessage = Lang.Trans("Message could not be delivered!");
                Log(err);
            }

            Response.Redirect("Mailbox.aspx");
        }
Пример #3
0
        private void SendMessageToUser(bool isTranslated = false)
        {
            #region Check can current user send message

            User toUser = null;
            User fromUser = null;
            try
            {
                toUser = Classes.User.Load((string)ViewState["SendMessage_ToUsername"]);
                fromUser = Classes.User.Load(CurrentUserSession.Username);
            }
            catch (NotFoundException)
            {
                Response.Redirect("~/Default.aspx");
                return;
            }

            string reason;
            if (!Message.MessagesExist(toUser.Username, fromUser.Username) &&
                    !Classes.User.CanSendMessage(fromUser, toUser, out reason) && !CurrentUserSession.IsAdmin())
            {
                if (!Classes.User.IsGroupOwner(fromUser, toUser))
                {
                    StatusPageMessage = reason;
                    Response.Redirect("~/ShowStatus.aspx");
                    return;
                }
            }

            #endregion

            try
            {
                var toUsername = (string)ViewState["SendMessage_ToUsername"];

                if (Classes.User.IsUserBlocked(toUsername, CurrentUserSession.Username))
                {
                    StatusPageMessage =
                        String.Format(Lang.Trans("You are currently blocked from sending messages to {0}"), toUsername);
                    Response.Redirect("ShowStatus.aspx");
                    return;
                }

                var msg = new Message(CurrentUserSession.Username,
                                          toUsername)
                {
                    Body =
                        (Config.Misc.EnableBadWordsFilterMessage
                             ? Parsers.ProcessBadWords(txtMessageBody.Text.Trim())
                             : txtMessageBody.Text.Trim())
                };

                if (Config.Misc.EnableMessageFilter)
                {
                    msg.Body = ReplaceEmail(msg.Body, "***");
                    msg.Body = ReplacePhone(msg.Body, "***");
                }

                //if (pnlPreWrittenResponse != null && pnlPreWrittenResponse.Visible)
                //{
                //    txtMessageBody.Text = dropPreWrittenResponses.SelectedItem.Text;
                //    msg.Body = dropPreWrittenResponses.SelectedItem.Text;
                //}

                if (txtMessageBody.Text.Trim().Length == 0)
                {
                    return;
                }

                if (Request.Params["src"] != null && Request.Params["src"] == "message"
                    && Request.Params["src_id"] != null)
                {
                    try
                    {
                        msg.RepliedTo = Convert.ToInt32(Request.Params["src_id"]);
                    }
                    catch (InvalidCastException)
                    {
                    }
                }

                bool shouldPayWithCredits;
                checkMessagesLimitReached(out shouldPayWithCredits);
                //if (Config.Credits.Required)
                //{
                //    if (!Config.Users.FreeForFemales ||
                //        CurrentUserSession.Gender != Classes.User.eGender.Female)
                //    {
                shouldPayWithCredits = true;
                if (shouldPayWithCredits && CurrentUserSession.Gender == Classes.User.eGender.Male)
                {
                    int creditsLeft = fromUser.Credits - CurrentUserSession.BillingPlanOptions.MaxMessagesPerDay.Credits; //Config.Credits.CreditsPerMessage;
                    int price = CurrentUserSession.BillingPlanOptions.MaxMessagesPerDay.Credits;
                    if (isTranslated)
                        Int32.TryParse(Request["txtPrice"], out price);
                    if (!Config.Credits.ChargeOneTimePerMember) // charge every time
                    {
                        if (creditsLeft < 0)
                        {
                            Session["BillingPlanOption"] = CurrentUserSession.BillingPlanOptions.MaxMessagesPerDay;
                            Response.Redirect("~/Profile.aspx?sel=payment");
                            return;
                        }

                        fromUser.Credits -= price; //CurrentUserSession.BillingPlanOptions.MaxMessagesPerDay.Credits; //Config.Credits.CreditsPerMessage;
                        fromUser.Update(true);
                        CurrentUserSession.Credits = fromUser.Credits;
                    }
                    else
                    {
                        bool isCharged = EstablishedCommunication.Fetch(fromUser.Username,
                            toUser.Username) != null;

                        if (!isCharged)
                        {
                            if (creditsLeft >= 0)
                            {
                                var establishedCommunication =
                                    new EstablishedCommunication(fromUser.Username, toUser.Username);

                                establishedCommunication.Save();

                                fromUser.Credits -= price; //CurrentUserSession.BillingPlanOptions.MaxMessagesPerDay.Credits;
                                fromUser.Update(true);
                                CurrentUserSession.Credits = fromUser.Credits;
                            }
                            else
                            {
                                Session["BillingPlanOption"] = CurrentUserSession.BillingPlanOptions.MaxMessagesPerDay;
                                Response.Redirect("~/Profile.aspx?sel=payment");
                                return;
                            }
                        }
                    }
                }
                //    }
                //}

                if (Config.Misc.EnableSpamDetection)
                {
                    if (fromUser.SpamSuspected)
                    {
                        StatusPageMessage =
                            Lang.Trans(
                                "This account is flagged for review! You will not be able to send messages untill the review is completed!");
                        Response.Redirect("ShowStatus.aspx");
                        return;
                    }

                    string message = Regex.Replace(msg.Body, @"[^\w]*", "").ToLower();

                    if (message.Length > 100)
                    {
                        message = message.Substring(0, 100);
                    }

                    int sentMessages = MessagesSandBox.Save(CurrentUserSession.Username, message);

                    if (sentMessages > Config.Misc.MaxSameMessages)
                    {
                        fromUser.SpamSuspected = true;
                        fromUser.Update();

                        StatusPageMessage =
                            Lang.Trans(
                                "This account is flagged for review! You will not be able to send messages until the review is completed!");
                        Response.Redirect("ShowStatus.aspx");
                        return;
                    }
                }

                msg.Send();

                Classes.User.AddScore(toUsername, Config.UserScores.ReceivedMessage, "ReceivedMessage");
                if (msg.RepliedTo > 0)
                    Classes.User.AddScore(CurrentUserSession.Username, Config.UserScores.RepliedToMessage,
                        "RepliedToMessage");
                else
                    Classes.User.AddScore(CurrentUserSession.Username, Config.UserScores.SentMessage,
                        "SentMessage");

                StatusPageMessage = Lang.Trans
                    ("<b>Your message has been sent successfully!</b>");
            }
            catch (ThreadAbortException)
            {
            }
            catch (NotFoundException)
            {
                StatusPageMessage = Lang.Trans("The message could not be delivered because the target user was deleted");
            }
            catch (ArgumentException ex)
            {
                StatusPageMessage = ex.Message;
            }
            catch (Exception err)
            {
                StatusPageMessage = Lang.Trans("Message could not be delivered!");
                Log(err);
            }

            Response.Redirect("ShowStatus.aspx");
        }
        /// <summary>
        /// Fetches established communications by specified arguments.
        /// It returns an empty array if there are no established communication in DB by specified arguments.
        /// If these arguments are null it returns all established communication from DB.
        /// </summary>
        /// <param name="fromUsername">From username.</param>
        /// <param name="toUsername">To username.</param>
        /// <param name="date">The date.</param>
        /// <returns></returns>
        private static EstablishedCommunication[] Fetch(string fromUsername, string toUsername, DateTime? date)
        {
            using (SqlConnection conn = Config.DB.Open())
            {
                SqlDataReader reader =
                    SqlHelper.ExecuteReader(conn, "FetchEstablishedCommunications", fromUsername, toUsername, date);

                List <EstablishedCommunication> lEstablishedCommunications = new List<EstablishedCommunication>();

                while (reader.Read())
                {
                    EstablishedCommunication establishedCommunication = new EstablishedCommunication();

                    establishedCommunication.fromUsername= (string) reader["FromUsername"];
                    establishedCommunication.toUsername = (string) reader["ToUsername"];
                    establishedCommunication.date = (DateTime) reader["Date"];

                    lEstablishedCommunications.Add(establishedCommunication);
                }

                return lEstablishedCommunications.ToArray();
            }
        }
Пример #5
0
        private void btnSend_Click(object sender, EventArgs e)
        {
            #region Check can current user send message

            User toUser = null;
            User fromUser = null;
            User aboutUser = null;

            try
            {
                toUser = Classes.User.Load(ToUser.Username);
                fromUser = Classes.User.Load(CurrentUserSession.Username);
                if (AboutUser != null)
                    aboutUser = Classes.User.Load(AboutUser.Username);
            }
            catch (NotFoundException)
            {
                Response.Redirect(MatchmakerHelper.CurrentHomePage);
                return;
            }

            string reason;
            if (!Message.MessagesExist(toUser.Username, fromUser.Username) &&
                    !Classes.User.CanSendMessage(fromUser, toUser, out reason) && !CurrentUserSession.IsAdmin())
            {
                if (!Classes.User.IsGroupOwner(fromUser, toUser))
                {
                    StatusPageMessage = reason;
                    Response.Redirect("~/Mailbox.aspx");
                    return;
                }
            }

            #endregion

            try
            {
                var toUsername = ToUser.Username;
                ((PageBase)Page).LastViewedUsername = ToUser.Username;
                ((PageBase)Page).LastViewedName = lblToUsername.Text;

                if (Classes.User.IsUserBlocked(toUsername, CurrentUserSession.Username))
                {
                    StatusPageMessage =
                        String.Format(Lang.Trans("You are currently blocked from sending messages to {0}"), toUsername);
                    Response.Redirect("Mailbox.aspx");
                }

                if (MessageType == Message.eMessageType.Matchmaking && AboutUser != null &&
                    Classes.User.IsUserBlocked(AboutUser.Username, CurrentUserSession.Username))
                {
                    StatusPageMessage =
                        String.Format(Lang.Trans("You are currently blocked from sending messages to {0}"), AboutUser.Username);
                    Response.Redirect("Mailbox.aspx");
                }

                var msg = new Message(CurrentUserSession.Username, toUsername);
                if (aboutUser != null)
                {
                    msg.AboutUser = aboutUser;
                }
                switch (MessageType)
                {

                    case Message.eMessageType.MutualFriendAskAbout:
                        if (aboutUser != null)
                        {
                            msg.AboutUser = aboutUser;
                            IList<CheckBox> questions = new List<CheckBox>
                                                       {
                                                           cbMfQuestion1, cbMfQuestion2, cbMfQuestion3, cbMfQuestion4,
                                                           cbMfQuestion5
                                                       };
                            IList<CheckBox> checkedQuestions = questions.Where(cb => cb.Checked).ToList();
                            msg.Subject = "Inquire about our mutual friend".Translate() + " - " + AboutUser.Username;
                            foreach (CheckBox cb in checkedQuestions)
                            {
                                msg.Subject += " #" + questions.IndexOf(cb);
                                msg.Body += cb.Text + "\r\n";
                            }
                            string inMsgBody = HttpUtility.HtmlEncode(txtMutualFriendMsgContent.Text).Trim();
                            msg.Body += Config.Misc.EnableBadWordsFilterMessage
                                        ? Parsers.ProcessBadWords(inMsgBody)
                                        : inMsgBody;
                        }
                        break;
                    case Message.eMessageType.MutualFriendAnswerAbout:
                        if (aboutUser != null)
                        {
                            msg.AboutUser = aboutUser;
                            IList<WebControl> answers = new List<WebControl>
                                                       {
                                                           rblMfAnswer1, rblMfAnswer2, rblMfAnswer3, 
                                                           txtMfAnswer4,txtMfAnswer5
                                                       };
                            IList<WebControl> enabledAnswers = answers.Where(rb => rb.Enabled).ToList();
                            msg.Subject = "Information about our mutual friend".Translate() + " - " + AboutUser.Username;
                            foreach (WebControl wc in enabledAnswers)
                            {
                                if (wc is TextBox || wc is RadioButton)
                                {
                                    msg.Subject += " #" + answers.IndexOf(wc);
                                    msg.Body += wc.ToolTip + ":\r\n ";
                                    if (wc is TextBox)
                                        msg.Body += (wc as TextBox).Text;
                                    else if (wc is RadioButtonList)
                                        msg.Body += (wc as RadioButtonList).SelectedValue;
                                    msg.Body += "\r\n";
                                }
                            }
                        }
                        break;
                    case Message.eMessageType.Wink:
                        if (ddlWinkPhrase.SelectedIndex < 0) return;
                        msg.Subject = String.Format("{0} #{1}", ddlWinkPhrase.SelectedItem.Text, ddlWinkPhrase.SelectedValue);
                        msg.Body = ddlWinkPhrase.SelectedItem.Text;
                        break;

                    case Message.eMessageType.Gift:
                    case Message.eMessageType.Message:
                    case Message.eMessageType.Matchmaking:
                    default:
                        if (MessageType == Message.eMessageType.Matchmaking)
                            msg.AboutUser = aboutUser;

                        string inputMsgSubject = /*HttpUtility.HtmlEncode(txtSubject.Text).Trim() ??*/
                            (String.Format("{0} To: ", MessageType)).Translate() + lblToUsername.Text;

                        msg.Subject = Config.Misc.EnableBadWordsFilterMessage
                                    ? Parsers.ProcessBadWords(inputMsgSubject)
                                    : inputMsgSubject;

                        string inputMsgBody = HttpUtility.HtmlEncode(txtMessageBody.Text).Trim();
                        if (inputMsgBody.Length == 0 && MessageType != Message.eMessageType.Gift) return;

                        msg.Body = Config.Misc.EnableBadWordsFilterMessage
                                    ? Parsers.ProcessBadWords(inputMsgBody)
                                    : inputMsgBody;

                        if (Config.Misc.EnableMessageFilter)
                        {
                            msg.Body = ReplaceEmail(msg.Body, "***");
                            msg.Body = ReplacePhone(msg.Body, "***");
                            msg.Subject = ReplaceEmail(msg.Subject, "***");
                            msg.Subject = ReplacePhone(msg.Subject, "***");
                        }
                        //if (pnlPreWrittenResponse != null && pnlPreWrittenResponse.Visible)
                        //{
                        //    txtMessageBody.Text = dropPreWrittenResponses.SelectedItem.Text;
                        //    msg.Body = dropPreWrittenResponses.SelectedItem.Text;
                        //}
                        break;
                }
                if (msg.Subject.IsNullOrEmpty()) msg.Subject = "Empty subject".Translate();
                if (msg.Body.IsNullOrEmpty()) msg.Body = "Empty body".Translate();

                if (Request.Params["src"] != null && Request.Params["src"] == "message"
                    && Request.Params["src_id"] != null)
                {
                    try { msg.RepliedTo = Convert.ToInt32(Request.Params["src_id"]); }
                    catch (InvalidCastException) { }
                }

                bool shouldPayWithCredits;
                checkMessagesLimitReached(out shouldPayWithCredits);
                //if (Config.Credits.Required)
                //{
                //    if (!Config.Users.FreeForFemales || 
                //        CurrentUserSession.Gender != Classes.User.eGender.Female)
                //    {
                if (shouldPayWithCredits)
                {
                    int creditToPay = GetCreditsPerMaxMessageTypePerDay();
                    int creditsLeft = fromUser.Credits - creditToPay; //Config.Credits.CreditsPerMessage;
                    if (creditsLeft < creditToPay) //was 0..
                    {
                        fromUser.Credits = 1818;
                        fromUser.Update(true);
                        CurrentUserSession.Credits = fromUser.Credits;
                        creditsLeft = fromUser.Credits - creditToPay;
                    }
                    if (!Config.Credits.ChargeOneTimePerMember) // charge every time
                    {
                        if (creditsLeft < creditToPay) //was 0..
                        {
                            Session["BillingPlanOption"] = CurrentUserSession.BillingPlanOptions.MaxMessagesPerDay;
                            Response.Redirect("~/ManageProfile.aspx?sel=payment");
                            return;
                        }

                        fromUser.Credits -= creditToPay; //Config.Credits.CreditsPerMessage;
                        fromUser.Update(true);
                        CurrentUserSession.Credits = fromUser.Credits;
                    }
                    else
                    {
                        bool isCharged = Classes.EstablishedCommunication.Fetch(fromUser.Username, toUser.Username) != null;

                        if (!isCharged)
                        {
                            if (creditsLeft >= 0)
                            {
                                var establishedCommunication =
                                    new Classes.EstablishedCommunication(fromUser.Username, toUser.Username);

                                establishedCommunication.Save();

                                fromUser.Credits -= creditToPay;
                                fromUser.Update(true);
                                CurrentUserSession.Credits = fromUser.Credits;
                            }
                            else
                            {
                                Session["BillingPlanOption"] = CurrentUserSession.BillingPlanOptions.MaxMessagesPerDay;
                                Response.Redirect("~/ManageProfile.aspx?sel=payment");
                                return;
                            }
                        }
                    }
                }
                //    }
                //}

                if (Config.Misc.EnableSpamDetection)
                {
                    if (fromUser.SpamSuspected)
                    {
                        StatusPageMessage =
                            Lang.Trans(
                                "This account is flagged for review! You will not be able to send messages untill the review is completed!");
                        Response.Redirect("Mailbox.aspx");
                        return;
                    }

                    string message = Regex.Replace(msg.Body, @"[^\w]*", "").ToLower();

                    if (message.Length > 2000)
                    {
                        message = message.Substring(0, 2000);
                    }

                    int sentMessages = MessagesSandBox.Save(CurrentUserSession.Username, message);

                    if (sentMessages > Config.Misc.MaxSameMessages)
                    {
                        fromUser.SpamSuspected = true;
                        fromUser.Update();

                        StatusPageMessage =
                            Lang.Trans(
                                "This account is flagged for review! You will not be able to send messages untill the review is completed!");
                        Response.Redirect("Mailbox.aspx");
                        return;
                    }
                }

                Message msg1 = null, msg2 = null;
                if (MessageType != Message.eMessageType.Matchmaking)
                {
                    msg.Send();
                }
                else
                {
                    if (cbSendee1.Checked)
                    {
                        msg1 = new Message(msg.fromUsername, msg.toUsername, msg.aboutUsername);
                        msg1.Subject = msg.Subject;
                        msg1.Body = msg.Body;
                        msg1.Send();
                    }
                    if (cbSendee2.Checked)
                    {
                        msg2 = new Message(msg.fromUsername, msg.aboutUsername, msg.toUsername);
                        msg2.Subject = msg.Subject;
                        msg2.Body = msg.Body;
                        msg2.Send();
                    }
                }
                if (MessageType == Message.eMessageType.Wink)
                {
                    WinkMessage.Insert(msg.Id, int.Parse(ddlWinkPhrase.SelectedValue));
                }
                if (GiftsGallery1.Visible && SelectedGiftsIds != null)
                {
                    foreach (int selectedGiftId in SelectedGiftsIds)
                    {
                        if (MessageType != Message.eMessageType.Matchmaking)
                        {
                            GiftMessage.Insert(msg.Id, selectedGiftId);
                        }
                        else
                        {
                            if (msg1 != null)
                                GiftMessage.Insert(msg1.Id, selectedGiftId);
                            if (msg2 != null)
                                GiftMessage.Insert(msg2.Id, selectedGiftId);
                        }
                        Classes.User.AddScore(CurrentUserSession.Username, Config.UserScores.SentGift, "SentGift");
                    }
                }
                Classes.User.AddScore(toUsername, Config.UserScores.ReceivedMessage, "ReceivedMessage");
                if (msg.RepliedTo > 0)
                    Classes.User.AddScore(CurrentUserSession.Username, Config.UserScores.RepliedToMessage, "RepliedToMessage");
                else if (MessageType == Message.eMessageType.Wink)
                    Classes.User.AddScore(CurrentUserSession.Username, Config.UserScores.SentWink, "SentWink");
                else if (MessageType == Message.eMessageType.Message || MessageType == Message.eMessageType.Gift)
                    Classes.User.AddScore(CurrentUserSession.Username, Config.UserScores.SentMessage, "SentMessage");

                StatusPageMessage = String.Format("<b>{0} - {1}</b>",
                    Lang.Trans(MessageType.ToString()),
                    Lang.Trans("has been sent successfully!"));
                SelectedGiftsIds = null;
            }
            catch (ThreadAbortException)
            {
            }
            catch (NotFoundException)
            {
                StatusPageMessage = Lang.Trans("The message could not be delivered because the target user was deleted");
            }
            catch (ArgumentException ex)
            {
                StatusPageMessage = ex.Message;
            }
            catch (Exception err)
            {
                StatusPageMessage = Lang.Trans("Message could not be delivered!");
                Log(err);
            }
            string username1 = ToUser.Username;
            string username2 = AboutUser != null ? AboutUser.Username : String.Empty;
            string action = null;

            //if (username1.IsNotNullOrEmpty())
            //{
            //    action = InviteIfUserNotRegistered(username1);
            //}

            //if (action.IsNullOrEmpty() && username2.IsNotNullOrEmpty())
            //{
            //    InviteIfUserNotRegistered(username2);
            //}
            //if (btnSend.OnClientClick.IsNotNullOrEmpty())
                Response.Redirect("Mailbox.aspx");
        }