private void CreateRequest(MemberInvitations model)
        {
            MemberRequests itm = new MemberRequests();

            Guid val;

            do
            {
                val = System.Guid.NewGuid();
            } while (Data.Helper.NHibernateHelper.UniqueResult<MemberRequests>("Guid", "Guid", val.ToString()) != null);

            itm.Guid = val.ToString();
            itm.Senderid = model.Senderid;
            itm.Recipientid = Data.Helper.NHibernateHelper.UniqueResult<MemberDetails>(null, "Id", LoggedInUserKey);
            itm.TargetPageid = model.TargetPageid;
            itm.Type = model.Type;
            itm.Createdate = DateTime.Now;
            itm.Status = 1;

            Data.Helper.NHibernateHelper.Save<MemberRequests>(itm);
        }
        public ActionResult Invite(int? id, AppConstants.InviteTypes type, Data.Entity.MemberInvitations model)
        {
            try
            {
                int _senderId = LoggedInUserKey;

                if ((model.Senderid != null) && (model.Senderid.Id != 0) && (model.Senderid.Id != -1))
                    _senderId = model.Senderid.Id;

                MemberInvitations itm = new MemberInvitations();

                Guid val;

                do
                {
                    val = System.Guid.NewGuid();
                } while (Data.Helper.NHibernateHelper.UniqueResult<MemberInvitations>("Guid", "Guid", val.ToString()) != null);

                itm.Guid = val.ToString();
                itm.Senderid = Data.Helper.NHibernateHelper.UniqueResult<MemberDetails>(null, "Id", _senderId);
                itm.Email = model.Email;
                itm.Type = (int)type;
                itm.Createdate = DateTime.Now;
                itm.TargetPageid = id;
                itm.Status = 1;

                try
                {
                    string[] msgParam = new string[4];

                    string strMsg = "Hello,\n\n {0} has requested you to join Parichay. \n\n Please click the following link to sign up if you do not have an account: \n {1} \n\n Please click on following link to acknowledge if you already have an account:\n {2} \n\n {3} \n\n Thanks & Regards,\n Webmasters \n Parichay";

                    msgParam[0] = itm.Senderid.Givennm;
                    msgParam[1] = AppConstants.BaseSiteUrl.TrimEnd('/') + Url.Action("Register", "Account");
                    msgParam[2] = AppConstants.BaseSiteUrl.TrimEnd('/') + Url.Action("AckInvite", new { id = itm.Guid });
                    msgParam[3] = string.IsNullOrEmpty(model.UserMessage) ? "" : "\n----------\n" + model.UserMessage + "\n----------\n";

                    strMsg = string.Format(strMsg, msgParam);

                    SendMail(model.Email, itm.Senderid.Givennm + " : Request to Join Parichay", strMsg);
                    //SendMail(itm.Senderid.PEmail, itm.Senderid.Givennm + " : Request to Join Parichay", strMsg);
                }
                catch (Exception exc1)
                {
                    Data.Helper.NHibernateHelper.Log(new Exception("Error sending Connect Invitation Email=>", exc1));
                }

                Data.Helper.NHibernateHelper.Save<MemberInvitations>(itm);

                TempData["message"] = "Invitation sent successfully.";
            }
            catch (Exception exc1)
            {
                TempData["message"] = "Unable to invite friend. Error:" + exc1.Message;
            }

            model.MyInvites = Data.Helper.NHibernateHelper.ConvertToListOf<MemberInvitations>(Data.Helper.NHibernateHelper.Find("select distinct a from MemberInvitations a where a.Senderid = ? or a.Email = ?", new object[] { LoggedInUserKey, LoggedInUserEmail }, new NHibernate.Type.IType[] { NHibernate.NHibernateUtil.Int32, NHibernate.NHibernateUtil.String }, false));

            return (View(model));
        }