Ejemplo n.º 1
0
        private ConfirmEnum DoOnlineGiving(string transactionReturn)
        {
            var p = List[0];
            if (p.IsNew)
            {
                p.AddPerson(null, p.org.EntryPointId ?? 0);
            }

            var desc = $"{p.person.Name}; {p.person.PrimaryAddress}; {p.person.PrimaryZip}";
            var staff = DbUtil.Db.StaffPeopleForOrg(org.OrganizationId)[0];
            var body = GivingConfirmation.PostAndBuild(DbUtil.Db, staff, p.person, p.setting.Body, p.org.OrganizationId, p.FundItemsChosen(), Transaction, desc,
                p.setting.DonationFundId);

            if (!Transaction.TransactionId.HasValue())
            {
                Transaction.TransactionId = transactionReturn;
                if (testing == true && !Transaction.TransactionId.Contains("(testing)"))
                {
                    Transaction.TransactionId += "(testing)";
                }
            }
            var contributionemail = (from ex in p.person.PeopleExtras
                                     where ex.Field == "ContributionEmail"
                                     select ex.Data).SingleOrDefault();
            if (contributionemail.HasValue())
            {
                contributionemail = (contributionemail ?? "").Trim();
            }

            if (Util.ValidEmail(contributionemail))
            {
                Log("UsingSpecialEmail");
            }
            else
            {
                contributionemail = p.person.FromEmail;
            }

            MailAddress from = null;
            if (!Util.TryGetMailAddress(DbUtil.Db.StaffEmailForOrg(p.org.OrganizationId), out from))
            {
                from = GetAdminMailAddress();
            }

            var m = new EmailReplacements(DbUtil.Db, body, from);
            body = m.DoReplacements(DbUtil.Db, p.person);

            DbUtil.Db.EmailFinanceInformation(from, p.person, p.setting.Subject, body);
            DbUtil.Db.EmailFinanceInformation(contributionemail, DbUtil.Db.StaffPeopleForOrg(p.org.OrganizationId),
                "online giving contribution received",
                $"see contribution records for {p.person.Name} ({p.PeopleId}) {Util.Host}");
            if (p.CreatingAccount)
            {
                p.CreateAccount();
            }

            return ConfirmEnum.Confirm;
        }
Ejemplo n.º 2
0
        public void Confirm(Controller controller)
        {
            var details = ViewExtensions2.RenderPartialViewToString(controller, "ManageGiving/EmailConfirmation", this);

            var staff = DbUtil.Db.StaffPeopleForOrg(orgid)[0];

            var contributionEmail = (from ex in DbUtil.Db.PeopleExtras
                                     where ex.Field == "ContributionEmail"
                                     where ex.PeopleId == person.PeopleId
                                     select ex.Data).SingleOrDefault();

            if (!Util.ValidEmail(contributionEmail))
            {
                contributionEmail = person.FromEmail;
            }

            if (!string.IsNullOrEmpty(Setting.Body))
            {
                var text = Setting.Body.Replace("{church}", DbUtil.Db.Setting("NameOfChurch", "church"),
                                                ignoreCase: true);
//            text = text.Replace("{name}", person.Name, ignoreCase: true);
                text = text.Replace("{date}", DateTime.Now.ToString("d"), ignoreCase: true);
                text = text.Replace("{email}", person.EmailAddress, ignoreCase: true);
                text = text.Replace("{phone}", person.HomePhone.FmtFone(), ignoreCase: true);
                text = text.Replace("{contact}", staff.Name, ignoreCase: true);
                text = text.Replace("{contactemail}", staff.EmailAddress, ignoreCase: true);
                text = text.Replace("{contactphone}", Organization.PhoneNumber.FmtFone(), ignoreCase: true);
                text = text.Replace("{details}", details, ignoreCase: true);

                var from = Util.TryGetMailAddress(DbUtil.Db.StaffEmailForOrg(orgid));
                var mm   = new EmailReplacements(DbUtil.Db, text, from);
                text = mm.DoReplacements(DbUtil.Db, person);

                Util.SendMsg(Util.SysFromEmail, Util.Host, from, Setting.Subject, text,
                             Util.EmailAddressListFromString(contributionEmail), 0, pid);
            }

            Util.SendMsg(Util.SysFromEmail, Util.Host, Util.TryGetMailAddress(contributionEmail),
                         "Managed Giving",
                         $"Managed giving for {person.Name} ({pid})",
                         Util.EmailAddressListFromString(DbUtil.Db.StaffEmailForOrg(orgid)),
                         0, pid);

            var msg = GetThankYouMessage(@"<p>Thank you {first}, for managing your recurring giving</p>
<p>You should receive a confirmation email shortly.</p>");

            msg             = msg.Replace("{first}", person.PreferredName, ignoreCase: true);
            ThankYouMessage = msg;
        }
Ejemplo n.º 3
0
        public ActionResult Application(int orgid, int peopleid, string content)
        {
#if DEBUG2
            var c            = System.IO.File.ReadAllText(Server.MapPath("/Application.html"));
            var replacements = new EmailReplacements(DbUtil.Db, c, null);
#else
            var c = DbUtil.Db.Content(content);
            if (c == null)
            {
                return(Message("no content at " + content));
            }
            var replacements = new EmailReplacements(DbUtil.Db, c.Body, null);
#endif
            var p = DbUtil.Db.LoadPersonById(peopleid);
            DbUtil.Db.SetCurrentOrgId(orgid);
            ViewBag.html = replacements.DoReplacements(DbUtil.Db, p);
            return(View());
        }
Ejemplo n.º 4
0
        private static void ValidateEmailReplacementCodes(CMSDataContext db, string emailText, MailAddress fromAddress)
        {
            var er = new EmailReplacements(db, emailText, fromAddress);

            er.DoReplacements(db, DbUtil.Db.LoadPersonById(Util.UserPeopleId.Value));
        }
Ejemplo n.º 5
0
        private ConfirmEnum ConfirmTransaction(OnlineRegModel m, string transactionId)
        {
            m.ParseSettings();
            if (m.List.Count == 0)
            {
                throw new Exception(" unexpected, no registrants found in confirmation");
            }
            var ret           = ConfirmEnum.Confirm;
            var managingsubs  = m.ManagingSubscriptions();
            var choosingslots = m.ChoosingSlots();
            var t             = m.Transaction;

            if (t == null && !managingsubs && !choosingslots)
            {
                m.HistoryAdd("ConfirmTransaction");
                m.UpdateDatum(completed: true);
                var pf = PaymentForm.CreatePaymentForm(m);
                t        = pf.CreateTransaction(DbUtil.Db);
                m.TranId = t.Id;
            }
            if (t != null)
            {
                ViewBag.message = t.Message;
            }

            if (m.org != null && m.org.RegistrationTypeId == RegistrationTypeCode.CreateAccount)
            {
                m.List[0].CreateAccount();
                ret = ConfirmEnum.ConfirmAccount;
            }
            else if (m.OnlineGiving())
            {
                var p = m.List[0];
                if (p.IsNew)
                {
                    p.AddPerson(null, p.org.EntryPointId ?? 0);
                }

                var staff = DbUtil.Db.StaffPeopleForOrg(p.org.OrganizationId)[0];
                var text  = p.setting.Body.Replace("{church}", DbUtil.Db.Setting("NameOfChurch", "church"), ignoreCase: true);
                text = text.Replace("{amt}", (t.Amt ?? 0).ToString("N2"));
                text = text.Replace("{date}", DateTime.Today.ToShortDateString());
                text = text.Replace("{tranid}", t.Id.ToString());
                //text = text.Replace("{name}", p.person.Name);
                text = text.Replace("{account}", "");
                text = text.Replace("{email}", p.person.EmailAddress);
                text = text.Replace("{phone}", p.person.HomePhone.FmtFone());
                text = text.Replace("{contact}", staff.Name);
                text = text.Replace("{contactemail}", staff.EmailAddress);
                text = text.Replace("{contactphone}", p.org.PhoneNumber.FmtFone());
                var re    = new Regex(@"(?<b>.*?)<!--ITEM\sROW\sSTART-->(?<row>.*?)\s*<!--ITEM\sROW\sEND-->(?<e>.*)", RegexOptions.Singleline | RegexOptions.IgnorePatternWhitespace);
                var match = re.Match(text);
                var b     = match.Groups["b"].Value;
                var row   = match.Groups["row"].Value.Replace("{funditem}", "{0}").Replace("{itemamt}", "{1:N2}");
                var e     = match.Groups["e"].Value;
                var sb    = new StringBuilder(b);

                var desc = "{0}; {1}; {2}".Fmt(
                    p.person.Name,
                    p.person.PrimaryAddress,
                    p.person.PrimaryZip);
                foreach (var g in p.FundItemsChosen())
                {
                    if (g.amt > 0)
                    {
                        sb.AppendFormat(row, g.desc, g.amt);
                        p.person.PostUnattendedContribution(DbUtil.Db, g.amt, g.fundid, desc, tranid: t.Id);
                    }
                }
                t.TransactionPeople.Add(new TransactionPerson
                {
                    PeopleId = p.person.PeopleId,
                    Amt      = t.Amt,
                    OrgId    = m.Orgid,
                });
                t.Financeonly = true;
                if (t.Donate > 0)
                {
                    var fundname = DbUtil.Db.ContributionFunds.Single(ff => ff.FundId == p.setting.DonationFundId).FundName;
                    sb.AppendFormat(row, fundname, t.Donate);
                    t.Fund = p.setting.DonationFund();
                    p.person.PostUnattendedContribution(DbUtil.Db, t.Donate ?? 0, p.setting.DonationFundId, desc, tranid: t.Id);
                }
                sb.Append(e);
                if (!t.TransactionId.HasValue())
                {
                    t.TransactionId = transactionId;
                    if (m.testing == true && !t.TransactionId.Contains("(testing)"))
                    {
                        t.TransactionId += "(testing)";
                    }
                }
                var contributionemail = (from ex in p.person.PeopleExtras
                                         where ex.Field == "ContributionEmail"
                                         select ex.Data).SingleOrDefault();
                if (contributionemail.HasValue())
                {
                    contributionemail = (contributionemail ?? "").Trim();
                }
                if (!Util.ValidEmail(contributionemail))
                {
                    contributionemail = p.person.FromEmail;
                }


                var body = sb.ToString();
                var from = Util.TryGetMailAddress(DbUtil.Db.StaffEmailForOrg(p.org.OrganizationId));
                var mm   = new EmailReplacements(DbUtil.Db, body, from);
                body = mm.DoReplacements(p.person);

                Util.SendMsg(Util.SysFromEmail, Util.Host, from, p.setting.Subject, body,
                             Util.EmailAddressListFromString(contributionemail), 0, p.PeopleId);
                DbUtil.Db.Email(contributionemail, DbUtil.Db.StaffPeopleForOrg(p.org.OrganizationId),
                                "online giving contribution received",
                                "see contribution records for {0} ({1})".Fmt(p.person.Name, p.PeopleId));
                if (p.CreatingAccount == true)
                {
                    p.CreateAccount();
                }
            }
            else if (managingsubs)
            {
                m.ConfirmManageSubscriptions();
                ret = ConfirmEnum.ConfirmAccount;
            }
            else if (choosingslots)
            {
                m.ConfirmPickSlots();
                m.URL = null;
                ViewBag.ManagingVolunteer = true;
                ViewBag.CreatedAccount    = m.List[0].CreatingAccount;
                ret = ConfirmEnum.ConfirmAccount;
            }
            else if (m.OnlinePledge())
            {
                m.SendLinkForPledge();
                ViewBag.CreatedAccount = m.List[0].CreatingAccount;
                ret = ConfirmEnum.ConfirmAccount;
            }
            else if (m.ManageGiving())
            {
                m.SendLinkToManageGiving();
                ret = ConfirmEnum.ConfirmAccount;
            }
            else if (t.TransactionGateway.ToLower() == "serviceu")
            {
                t.TransactionId = transactionId;
                if (m.testing == true && !t.TransactionId.Contains("(testing)"))
                {
                    t.TransactionId += "(testing)";
                }
                t.Message  = "Transaction Completed";
                t.Approved = true;
                m.EnrollAndConfirm();
                if (m.List.Any(pp => pp.PeopleId == null))
                {
                    LogOutOfOnlineReg();
                    throw new Exception("no person");
                }
                m.UseCoupon(t.TransactionId, t.Amt ?? 0);
            }
            else
            {
                if (!t.TransactionId.HasValue())
                {
                    t.TransactionId = transactionId;
                    if (m.testing == true && !t.TransactionId.Contains("(testing)"))
                    {
                        t.TransactionId += "(testing)";
                    }
                }
                m.EnrollAndConfirm();
                if (m.List.Any(pp => pp.PeopleId == null))
                {
                    LogOutOfOnlineReg();
                    throw new Exception("no person");
                }
                m.UseCoupon(t.TransactionId, t.Amt ?? 0);
            }
            if (m.IsCreateAccount() || m.ManagingSubscriptions())
            {
                m.email = m.List[0].person.EmailAddress;
            }
            else
            {
                m.email = m.List[0].EmailAddress;
            }
            ViewBag.email = m.email;

            if (m.masterorgid.HasValue && m.Orgid.HasValue && !m.settings[m.Orgid.Value].Subject.HasValue())
            {
                ViewBag.orgname = m.masterorg.OrganizationName;
            }
            else
            {
                ViewBag.orgname = m.org != null ? m.org.OrganizationName : m.masterorg.OrganizationName;
            }

            LogOutOfOnlineReg();
            return(ret);
        }
Ejemplo n.º 6
0
        private ConfirmEnum DoOnlineGiving(string transactionReturn)
        {
            var p = List[0];

            if (p.IsNew)
            {
                p.AddPerson(null, p.org.EntryPointId ?? 0);
            }

            var staff = DbUtil.Db.StaffPeopleForOrg(p.org.OrganizationId)[0];
            var text  = p.setting.Body;

            text = text.Replace("{church}", DbUtil.Db.Setting("NameOfChurch", "church"), ignoreCase: true);
            text = text.Replace("{amt}", (Transaction.Amt ?? 0).ToString("N2"));
            text = text.Replace("{date}", DateTime.Today.ToShortDateString());
            text = text.Replace("{tranid}", Transaction.Id.ToString());
            text = text.Replace("{account}", "");
            text = text.Replace("{email}", p.person.EmailAddress);
            text = text.Replace("{phone}", p.person.HomePhone.FmtFone());
            text = text.Replace("{contact}", staff.Name);
            text = text.Replace("{contactemail}", staff.EmailAddress);
            text = text.Replace("{contactphone}", p.org.PhoneNumber.FmtFone());
            var re = new Regex(@"(?<b>.*?)<!--ITEM\sROW\sSTART-->(?<row>.*?)\s*<!--ITEM\sROW\sEND-->(?<e>.*)",
                               RegexOptions.Singleline | RegexOptions.IgnorePatternWhitespace);
            var match = re.Match(text);
            var b     = match.Groups["b"].Value;
            var row   = match.Groups["row"].Value.Replace("{funditem}", "{0}").Replace("{itemamt}", "{1:N2}");
            var e     = match.Groups["e"].Value;
            var sb    = new StringBuilder(b);

            var desc = $"{p.person.Name}; {p.person.PrimaryAddress}; {p.person.PrimaryZip}";

            foreach (var g in p.FundItemsChosen())
            {
                if (g.amt > 0)
                {
                    sb.AppendFormat(row, g.desc, g.amt);
                    p.person.PostUnattendedContribution(DbUtil.Db, g.amt, g.fundid, desc, tranid: Transaction.Id);
                }
            }
            Transaction.TransactionPeople.Add(new TransactionPerson
            {
                PeopleId = p.person.PeopleId,
                Amt      = Transaction.Amt,
                OrgId    = Orgid,
            });
            Transaction.Financeonly = true;
            if (Transaction.Donate > 0)
            {
                var fundname = DbUtil.Db.ContributionFunds.Single(ff => ff.FundId == p.setting.DonationFundId).FundName;
                sb.AppendFormat(row, fundname, Transaction.Donate);
                Transaction.Fund = p.setting.DonationFund();
                p.person.PostUnattendedContribution(DbUtil.Db, Transaction.Donate ?? 0, p.setting.DonationFundId, desc,
                                                    tranid: Transaction.Id);
                Log("PostedContribution");
            }
            sb.Append(e);
            if (!Transaction.TransactionId.HasValue())
            {
                Transaction.TransactionId = transactionReturn;
                if (testing == true && !Transaction.TransactionId.Contains("(testing)"))
                {
                    Transaction.TransactionId += "(testing)";
                }
            }
            var contributionemail = (from ex in p.person.PeopleExtras
                                     where ex.Field == "ContributionEmail"
                                     select ex.Data).SingleOrDefault();

            if (contributionemail.HasValue())
            {
                contributionemail = (contributionemail ?? "").Trim();
            }

            if (Util.ValidEmail(contributionemail))
            {
                Log("UsingSpecialEmail");
            }
            else
            {
                contributionemail = p.person.FromEmail;
            }

            var body = sb.ToString();
            var from = Util.TryGetMailAddress(DbUtil.Db.StaffEmailForOrg(p.org.OrganizationId));
            var mm   = new EmailReplacements(DbUtil.Db, body, @from);

            body = mm.DoReplacements(DbUtil.Db, p.person);

            Util.SendMsg(Util.SysFromEmail, Util.Host, @from, p.setting.Subject, body,
                         Util.EmailAddressListFromString(contributionemail), 0, p.PeopleId);
            DbUtil.Db.Email(contributionemail, DbUtil.Db.StaffPeopleForOrg(p.org.OrganizationId),
                            "online giving contribution received",
                            $"see contribution records for {p.person.Name} ({p.PeopleId})");
            if (p.CreatingAccount)
            {
                p.CreateAccount();
            }
            return(ConfirmEnum.Confirm);
        }