Exemplo n.º 1
0
        //[NoCache] cache so that if users enter the same emai twice nothing happens
        public JsonResult InviteViaEmailAJAX(string e)
        {
            string emailAddress = e;

            if(!Validate.Email(emailAddress))
            {
                ValidationErrors.Add("Invalid Email", Errors.INVALID_EMAIL);
            }

            CommitResponse response = new CommitResponse() { success = false };
            if (ValidationErrors.Count == 0)
            {
                //Capture the Invitation
                accountInterface.CaptureEmailInvite(MemberInfo.MemberID, emailAddress, CurrentEvent.EventID);

                //Send out the email
                Dictionary<string, string> replaceValues = new Dictionary<string, string>();
                replaceValues.Add("INVITERS_EMAIL", MemberInfo.Email);
                string gameName = gameInterface.GetGameByID(CurrentEvent.GameID).GameName;
                replaceValues.Add("GAME_NAME", gameName);
                string eventTypeName = eventInterface.GetEventTypeByID(CurrentEvent.EventID).EventTypeName;
                replaceValues.Add("EVENT_TYPE", eventTypeName);
                replaceValues.Add("EVENT_LINK", CurrentEvent.GenerateEventURL(System.Web.HttpContext.Current));

                try
                {
                    SMTPEmail.SMTPEMailS email = new SMTPEmail.SMTPEMailS(replaceValues);
                    string emailFileLocation = Server.MapPath("~/Static/InviteEmail.txt");
                    response.success = email.SendEmailFromFile(new string[] { emailAddress }, "*****@*****.**", "A friend has invited you to a Group", emailFileLocation, null, false);
                }
                catch (Exception ex)
                {
                    //TODO: We really want to know if this fails. Its possible to capture all the failures and then email them out later
                }

            }

            return new JsonResult() { Data = response };
        }