public ActionResult ReplyMessage(int id, int rId, int rUrl, MemberMessage model)
        {
            model.ParentId = new MemberMessage() { Id = id };
                model.Recipient = new MemberDetails() { Id = rId };
                model.rUrl = rUrl;

            return AddMessage(model);
        }
        public ActionResult AddMessage(MemberMessage model)
        {
            var result = new JsonResponse();
            if (string.IsNullOrEmpty(model.Text))
            {
                result.isSuccessful = false;
                TempData["message"] = result.errorMessage = "Message cannot be blank.";
            }
            else
            {
                //update the database
                if (IsUserAuthenticated)
                {
                    try
                    {

                        MemberDetails thisUsr = NHibernateHelper.UniqueResult<MemberDetails>(null, "Id", LoggedInUserKey);

                        var msg = new MemberMessage
                        {
                            Text = model.Text.Replace("\r\n", " "),
                            Modifiedon = DateTime.Now.ToUniversalTime(),
                            Createdon = DateTime.Now.ToUniversalTime(),
                            Sender = thisUsr,
                            Type = ((int)model.Type),
                            Isprivate = 0,
                            Source = "parichay",
                            Recipient = thisUsr
                        };

                        if (model.ParentId != null)
                        {
                            msg.ParentId = NHibernateHelper.UniqueResult<MemberMessage>(null, "Id", model.ParentId.Id);
                        }
                        if (model.Recipient != null)
                        {
                            MemberDetails recUsr = NHibernateHelper.UniqueResult<MemberDetails>(null, "Id", model.Recipient.Id);
                            if (recUsr == null)
                            {
                                throw new Exception("This user do not have profile information. Message cannot be sent.");
                            }
                            else
                            {
                                msg.Recipient = recUsr;
                            }

                        }

                        NHibernateHelper.Save<MemberMessage>(msg);

                        //Sending Notify Now
                        try
                        {
                            if (msg.Sender.Id != msg.Recipient.Id)
                            {
                                string msgUrl = "<a href='" + Url.Action("MsgDtl", "Message", new { id = msg.Id }) + "' >reply</a>";
                                Alert(msg.Recipient.Id, string.Format("You have received a ({0}) to from: {1}", msgUrl, msg.Sender.Givennm));
                            }
                        }
                        catch (Exception ex1)
                        {

                            Data.Helper.NHibernateHelper.Log(new Exception("Error Sending Message Alert=>", ex1));
                        }

                        result.Id = msg.Id.ToString();

                        result.isSuccessful = true;
                        TempData["message"] = result.responseText = "Message Sent Successfully";
                    }
                    catch (Exception excp1)
                    {
                        Data.Helper.NHibernateHelper.Log(new Exception("Error Sending Message=>", excp1));
                        result.isSuccessful = false;
                        TempData["message"] = result.errorMessage = "Failed to save message. Error: " + excp1.Message;
                    }
                }
                else
                {
                    result.isSuccessful = false;
                    TempData["message"] = result.errorMessage = "You must be logged in to post a message";
                }
            }
            if (IsJsonRequest())
            { return Json(result); }
            else
            {
                    return RedirectToAction("Index",((Parichay.AppConstants.ReturnContollerHomes)model.rUrl).ToString());
            }
        }