public virtual ActionResult Write(int playerId, int responseTo = -1)
        {
            var myMembershipId = User.Identity.GetUserId();
            var me             = PlayerProcedures.GetPlayerFromMembership(myMembershipId);
            var sendingTo      = PlayerProcedures.GetPlayer(playerId);
            var output         = new MessageSubmitViewModel();

            output.SenderId      = me.Id;
            output.ReceiverId    = playerId;
            output.responseToId  = responseTo;
            output.SendingToName = sendingTo.GetFullName();

            if (DomainRegistry.Repository.FindSingle(new IsAccountLockedOut {
                userId = me.MembershipId
            }))
            {
                return(RedirectToAction(MVC.PvP.Play()));
            }

            if (TempData["MessageText"] != null && TempData["ErrorMessage"] != null)
            {
                // preserves what the user typed if coming from SendMessage
                output.MessageText   = TempData["MessageText"] as string;
                ViewBag.ErrorMessage = TempData["ErrorMessage"];
            }

            if (responseTo != -1)
            {
                try
                {
                    var msgRepliedTo = DomainRegistry.Repository.FindSingle(new GetMessage {
                        MessageId = responseTo, OwnerId = me.Id
                    });
                    output.RespondingToMsg = msgRepliedTo.MessageText;
                }
                catch (DomainException)
                {
                    TempData["Result"] = "You can't reply to this message since the original was not sent to you.";
                    return(RedirectToAction(MVC.Messages.Index()));
                }
            }

            return(View(MVC.Messages.Views.Write, output));
        }
        public virtual ActionResult SendMessage(MessageSubmitViewModel input)
        {
            var myMembershipId = User.Identity.GetUserId();
            var me             = PlayerProcedures.GetPlayerFromMembership(myMembershipId);
            var receiver       = PlayerProcedures.GetPlayer(input.ReceiverId);

            // assert player is not banned from chat
            if (me.IsBannedFromGlobalChat)
            {
                TempData["Error"]    = "You have been banned and cannot send any messages.";
                TempData["SubError"] = "If you feel this is in error or wish to make an appeal you may do so on the forums.";
                return(RedirectToAction(MVC.PvP.Play()));
            }

            // assert no blacklist exists
            if (BlacklistProcedures.PlayersHaveBlacklistedEachOther(me, receiver, "message"))
            {
                TempData["Error"]    = "This player has blacklisted you or is on your own blacklist.";
                TempData["SubError"] = "You cannot send messages to players who have blacklisted you.  Remove them from your blacklist or ask them to remove you from theirs.";
                return(RedirectToAction(MVC.PvP.Play()));
            }

            if (EffectProcedures.PlayerHasActiveEffect(me, CharacterPrankProcedures.HUSHED_EFFECT))
            {
                TempData["ErrorMessage"] = "You have been hushed and cannot currently send a message.  Try again once the effect has worn off.";
                TempData["MessageText"]  = input.MessageText;
                return(RedirectToAction(MVC.Messages.Write(input.ReceiverId, input.responseToId)));
            }

            if (input.MessageText.IsNullOrEmpty())
            {
                TempData["ErrorMessage"] = "You need to write something to send to this person.";
                TempData["MessageText"]  = input.MessageText;
                return(RedirectToAction(MVC.Messages.Write(input.ReceiverId, input.responseToId)));
            }

            if (input.MessageText.Length > 1000)
            {
                TempData["ErrorMessage"] = "Your message is too long.";
                TempData["MessageText"]  = input.MessageText;
                return(RedirectToAction(MVC.Messages.Write(input.ReceiverId, input.responseToId)));
            }

            MessageDetail repliedMsg = null;

            if (input.responseToId > 0)
            {
                repliedMsg = DomainRegistry.Repository.FindSingle(new GetMessage {
                    MessageId = input.responseToId, OwnerId = me.Id
                });
            }


            DomainRegistry.Repository.Execute(new CreateMessage
            {
                ReceiverId            = receiver.Id,
                SenderId              = me.Id,
                Text                  = input.MessageText,
                ReplyingToThisMessage = repliedMsg
            });

            NoticeService.PushNotice(receiver, "<b>" + me.GetFullName() + " has sent you a new message.</b>", NoticeService.PushType__PlayerMessage);

            TempData["Result"] = "Your message has been sent.";

            if (me.Mobility != PvPStatics.MobilityFull)
            {
                ItemProcedures.UpdateSouledItem(me);
            }

            return(RedirectToAction(MVC.Messages.Index()));
        }