コード例 #1
0
        private void SendNoDbEmail(Person goer, GoerSupporter gs)
        {
            var from = new MailAddress(goer.EmailAddress ?? goer.EmailAddress2, goer.Name);
            var db   = DbUtil.Db;

            try
            {
                var text = Body;

                text = text.Replace("{salutation}", gs.Salutation, true);
                text = text.Replace("{track}", "", true);
                var qs   = "OptOut/UnSubscribe/?gid=" + Util.EncryptForUrl($"{gs.Id}");
                var url  = db.ServerLink(qs);
                var link = $@"<a href=""{url}"">Unsubscribe</a>";
                text = text.Replace("{unsubscribe}", link, true);
                text = text.Replace("%7Bfromemail%7D", from.Address, true);
                var supportlink = db.ServerLink($"/OnlineReg/{OrgId}?gsid={gs.Id}");
                text = text.Replace("http://supportlink", supportlink, true);
                text = text.Replace("https://supportlink", supportlink, true);
                db.SendEmail(from, Subject, text, Util.ToMailAddressList(gs.NoDbEmail), gs.Id);
            }
            catch (Exception ex)
            {
                db.SendEmail(from, "sent emails - error", ex.ToString(),
                             Util.ToMailAddressList(from), gs.Id);
                throw;
            }
        }
コード例 #2
0
        public string TestSend()
        {
            var db = DbUtil.Db;
            var p  = db.LoadPersonById(Util.UserPeopleId.Value);

            try
            {
                db.CopySession();
                var from = new MailAddress(p.EmailAddress ?? p.EmailAddress2, p.Name);
                db.SetCurrentOrgId(OrgId);
                var gs = new GoerSupporter
                {
                    Created     = DateTime.Now,
                    Goer        = p,
                    Supporter   = p,
                    SupporterId = p.PeopleId,
                    GoerId      = p.PeopleId
                };
                var plist = new List <GoerSupporter> {
                    gs
                };
                db.SubmitChanges();
                var emailQueue = db.CreateQueueForSupporters(p.PeopleId, from, Subject, Body, null, plist, false);
                db.SendPeopleEmail(emailQueue.Id);
            }
            catch (Exception ex)
            {
                return(JsonConvert.SerializeObject(new { error = true, message = ex.Message }));
            }
            return(JsonConvert.SerializeObject(new { message = "Test Email Sent" }));
        }
コード例 #3
0
        private void SendNoDbEmail(Person goer, GoerSupporter gs)
        {
            var sysFromEmail = Util.SysFromEmail;
            var from         = new MailAddress(goer.EmailAddress ?? goer.EmailAddress2, goer.Name);

            try
            {
                var text = Body;
                //var aa = DbUtil.Db.DoReplacements(ref text, goer, null);

                text = text.Replace("{salutation}", gs.Salutation, ignoreCase: true);
                var qs   = "OptOut/UnSubscribe/?gid=" + Util.EncryptForUrl("{0}".Fmt(gs.Id));
                var url  = DbUtil.Db.ServerLink(qs);
                var link = @"<a href=""{0}"">Unsubscribe</a>".Fmt(url);
                text = text.Replace("{unsubscribe}", link, ignoreCase: true);
                text = text.Replace("%7Bfromemail%7D", from.Address, ignoreCase: true);
                text = text.Replace("http://supportlink", DbUtil.Db.ServerLink("/OnlineReg/{0}?gsid={1}".Fmt(OrgId, gs.Id)), ignoreCase: true);
                Util.SendMsg(sysFromEmail, DbUtil.Db.CmsHost, from, Subject, text, Util.ToMailAddressList(gs.NoDbEmail), gs.Id, null);
            }
            catch (Exception ex)
            {
                Util.SendMsg(sysFromEmail, DbUtil.Db.CmsHost, from, "sent emails - error", ex.ToString(),
                             Util.ToMailAddressList(from), gs.Id, null);
                throw;
            }
        }
コード例 #4
0
        public int AddRecipient(int?supporterid, string email)
        {
            var db = DbUtil.Db;
            var q  = from e in db.GoerSupporters
                     where e.GoerId == PeopleId
                     where e.SupporterId == supporterid || e.NoDbEmail == email
                     select e;
            var r = q.SingleOrDefault();

            if (r == null)
            {
                r = new GoerSupporter
                {
                    GoerId      = PeopleId,
                    SupporterId = supporterid,
                    NoDbEmail   = email,
                    Active      = true,
                    Created     = DateTime.Now
                };
                var supporter = db.People.SingleOrDefault(pp => pp.PeopleId == supporterid);
                var goer      = db.People.SingleOrDefault(pp => pp.PeopleId == PeopleId);
                if (supporter == null)
                {
                    r.Salutation = "Dear Friend";
                }
                else if (goer != null && goer.Age < 30 && (supporter.Age - goer.Age) > 10)
                {
                    r.Salutation = "Dear " + supporter.TitleCode + " " + supporter.LastName;
                }
                else
                {
                    r.Salutation = "Hi " + supporter.PreferredName;
                }

                db.GoerSupporters.InsertOnSubmit(r);
            }
            else
            {
                r.Active = true;
            }
            db.SubmitChanges();
            Recipients = GetRecipients();
            return(r.Id);
        }
コード例 #5
0
        public ActionResult Index(int?id, bool?testing, string email, bool?nologin, bool?login, string registertag, bool?showfamily, int?goerid, int?gsid, string source)
        {
            if (Util.IsDebug())
            {
                var q = from om in DbUtil.Db.OrganizationMembers
                        where om.OrganizationId == 89539 && om.PeopleId == 828612
                        select om;
                foreach (var om in q)
                {
                    om.Drop(DbUtil.Db, addToHistory: false);
                }
                //        DbUtil.Db.PurgePerson(om.PeopleId);
                //                var dr = DbUtil.Db.People.SingleOrDefault(mm => mm.Name == "David Roll");
                //                if (dr != null)
                //                    foreach (var mm in dr.Family.People)
                //                        if (mm.PeopleId != dr.PeopleId)
                //                            DbUtil.Db.PurgePerson(mm.PeopleId);
                DbUtil.Db.SubmitChanges();
            }
            if (DbUtil.Db.Roles.Any(rr => rr.RoleName == "disabled"))
            {
                return(Content("Site is disabled for maintenance, check back later"));
            }
            Response.NoCache();
            if (!id.HasValue)
            {
                return(Message("no organization"));
            }

            MobileAppMenuController.Source = source;
            var m = new OnlineRegModel()
            {
                Orgid = id
            };

            if (m.org == null && m.masterorg == null)
            {
                return(Message("invalid registration"));
            }

            GoerSupporter goerSupporter = null; // used for mission trips

            if (m.masterorg != null)
            {
                if (!OnlineRegModel.UserSelectClasses(m.masterorg).Any())
                {
                    return(Message("no classes available on this org"));
                }
            }
            else if (m.org != null)
            {
                if ((m.org.RegistrationTypeId ?? 0) == RegistrationTypeCode.None)
                {
                    return(Message("no registration allowed on this org"));
                }
                if (m.org.IsMissionTrip == true)
                {
                    if (gsid.HasValue) // this means that the person is a suppoter who got a support email
                    {
                        goerSupporter = DbUtil.Db.GoerSupporters.SingleOrDefault(gg => gg.Id == gsid);
                        if (goerSupporter != null)
                        {
                            m.GoerId          = goerSupporter.GoerId; // suppoert this particular goer
                            m.GoerSupporterId = gsid;
                        }
                        else
                        {
                            m.GoerId = 0; // allow this supporter to still select a goer
                        }
                    }
                    else if (goerid.HasValue)
                    {
                        m.GoerId = goerid;
                    }
                }
            }
            if (Request.Url != null)
            {
                m.URL = Request.Url.OriginalString;
            }

            SetHeaders(m);

            m.testing = testing == true || DbUtil.Db.Setting("OnlineRegTesting", Util.IsDebug() ? "true" : "false").ToBool();

            if (Util.ValidEmail(email) || login != true)
            {
                m.nologin = true;
            }

            if (m.nologin)
            {
                m.CreateList();
            }
            else
            {
                m.List = new List <OnlineRegPersonModel>();
            }

            if (Util.ValidEmail(email))
            {
                m.List[0].EmailAddress = email;
            }


            var pid = 0;

            if (registertag.HasValue())
            {
                var guid = registertag.ToGuid();
                if (guid == null)
                {
                    return(Message("invalid link"));
                }
                var ot = DbUtil.Db.OneTimeLinks.SingleOrDefault(oo => oo.Id == guid.Value);
                if (ot == null)
                {
                    return(Message("invalid link"));
                }
#if DEBUG
#else
                if (ot.Used)
                {
                    return(Message("link used"));
                }
#endif
                if (ot.Expires.HasValue && ot.Expires < DateTime.Now)
                {
                    return(Message("link expired"));
                }
                var a = ot.Querystring.Split(',');
                pid           = a[1].ToInt();
                m.registertag = registertag;
            }
            else if (User.Identity.IsAuthenticated)
            {
                pid = Util.UserPeopleId ?? 0;
            }

            if (pid > 0)
            {
                m.UserPeopleId = pid;
                var existingRegistration = m.GetExistingRegistration(pid);
                if (existingRegistration != null)
                {
                    TempData["er"] = m.UserPeopleId;
                    return(Redirect("/OnlineReg/Existing/" + existingRegistration.DatumId));
                }
                OnlineRegPersonModel p = null;
                if (showfamily != true)
                {
                    p = m.LoadExistingPerson(pid, 0);
                    OnlineRegPersonModelValidator.ValidateModelForFind(p, ModelState, m, 0);
                    p.LoggedIn = true;
                    if (m.masterorg == null)
                    {
                        if (m.List.Count == 0)
                        {
                            m.List.Add(p);
                        }
                        else
                        {
                            m.List[0] = p;
                        }
                    }
                }
                if (!ModelState.IsValid)
                {
                    return(View(m));
                }

                if (m.masterorg != null && m.masterorg.RegistrationTypeId == RegistrationTypeCode.ManageSubscriptions2)
                {
                    TempData["ms"] = m.UserPeopleId;
                    return(Redirect("/OnlineReg/ManageSubscriptions/{0}".Fmt(m.masterorgid)));
                }
                if (m.org != null && m.org.RegistrationTypeId == RegistrationTypeCode.ManageGiving)
                {
                    TempData["mg"] = m.UserPeopleId;
                    return(ManageGiving(m.Orgid.ToString(), m.testing));
                }
                if (m.org != null && m.org.RegistrationTypeId == RegistrationTypeCode.OnlinePledge)
                {
                    TempData["mp"] = m.UserPeopleId;
                    return(Redirect("/OnlineReg/ManagePledge/{0}".Fmt(m.Orgid)));
                }
                if (m.org != null && m.org.RegistrationTypeId == RegistrationTypeCode.ChooseVolunteerTimes)
                {
                    TempData["ps"] = m.UserPeopleId;
                    return(Redirect("/OnlineReg/ManageVolunteer/{0}".Fmt(m.Orgid)));
                }
                if (showfamily != true && p.org != null && p.Found == true)
                {
                    p.IsFilled = p.org.RegLimitCount(DbUtil.Db) >= p.org.Limit;
                    if (p.IsFilled)
                    {
                        ModelState.AddModelError(m.GetNameFor(mm => mm.List[0].Found), "Sorry, but registration is closed.");
                    }
                    if (p.Found == true)
                    {
                        p.FillPriorInfo();
                    }
                    p.CheckSetFee();
                    m.HistoryAdd("index, pid={0}, !showfamily, p.org, found=true".Fmt(pid));
                    return(View(m));
                }
                m.HistoryAdd("index, pid=" + pid);
                return(View(m));
            }
            m.HistoryAdd("index");
            return(View(m));
        }
コード例 #6
0
        public ActionResult SendLink(string id, FormCollection formCollection)
        {
            var li = new LinkInfo(CurrentDatabase, sendlinkSTR, landingSTR, id);

            if (li.error.HasValue())
            {
                return(Message(li.error));
            }

            try
            {
                if (!li.pid.HasValue)
                {
                    throw new Exception("missing peopleid");
                }

                if (!li.oid.HasValue)
                {
                    throw new Exception("missing orgid");
                }

                var queueid  = li.a[2].ToInt();
                var linktype = li.a[3]; // for supportlink, this will also have the goerid

                int?gsid = null;
                if (linktype.Contains("supportlink:"))
                {
                    gsid = linktype.Split(':')[1].ToInt();
                }

                Organization  oorg   = null;
                Person        person = null;
                string        personPreferredName;
                string        personEmailAddress;
                GoerSupporter gs = null;
                if (li.pid == 0)
                {
                    oorg = CurrentDatabase.Organizations.SingleOrDefault(o => o.OrganizationId == li.oid);
                    gs   = CurrentDatabase.GoerSupporters.SingleOrDefault(s => s.Id == gsid);
                    personPreferredName = string.Empty;
                    personEmailAddress  = gs.NoDbEmail;
                }
                else
                {
                    var q = (from pp in CurrentDatabase.People
                             where pp.PeopleId == li.pid
                             let org = CurrentDatabase.LoadOrganizationById(li.oid)
                                       select new { p = pp, org }).Single();

                    oorg   = q.org;
                    person = q.p;
                    personPreferredName = $"{person.PreferredName}, ";
                    personEmailAddress  = person.EmailAddress;
                }

                if (oorg == null && CurrentDatabase.Host == "trialdb")
                {
                    var oid = li.oid + Util.TrialDbOffset;
                    var q   = (from pp in CurrentDatabase.People
                               where pp.PeopleId == li.pid
                               let org = CurrentDatabase.LoadOrganizationById(oid)
                                         select new { p = pp, org }).Single();

                    oorg   = q.org;
                    person = q.p;
                    personPreferredName = $"{person.PreferredName}, ";
                    personEmailAddress  = person.EmailAddress;
                }

                if (oorg.RegistrationClosed == true || oorg.OrganizationStatusId == OrgStatusCode.Inactive)
                {
                    throw new Exception("sorry, registration has been closed");
                }

                if (oorg.RegistrationTypeId == RegistrationTypeCode.None)
                {
                    throw new Exception("sorry, registration is no longer available");
                }

                DbUtil.LogActivity($"{sendlinkSTR}{confirmSTR}", li.oid, li.pid);

                var    expires = DateTime.Now.AddMinutes(CurrentDatabase.Setting("SendlinkExpireMinutes", "30").ToInt());
                string action  = (linktype.Contains("supportlink") ? "support" : "register for");
                string minutes = CurrentDatabase.Setting("SendLinkExpireMinutes", "30");
                var    c       = DbUtil.Content(CurrentDatabase, "SendLinkMessage");
                if (c == null)
                {
                    c = new Content
                    {
                        Name  = "SendLinkMessage",
                        Title = "Your Link for {org}",
                        Body  = @"
<p>Here is your temporary <a href='{url}'>LINK</a> to {action} {org}.</p>

<p>This link will expire at {time} ({minutes} minutes).
You may request another link by clicking the link in the original email you received.</p>

<p>Note: If you did not request this link, please ignore this email,
or contact the church if you need help.</p>
"
                    };
                    CurrentDatabase.Contents.InsertOnSubmit(c);
                    CurrentDatabase.SubmitChanges();
                }
                var url = EmailReplacements.RegisterLinkUrl(CurrentDatabase,
                                                            li.oid.Value, li.pid.Value, queueid, linktype, expires);
                var subject = c.Title.Replace("{org}", oorg.OrganizationName);
                var msg     = c.Body.Replace("{org}", oorg.OrganizationName)
                              .Replace("{time}", expires.ToString("f"))
                              .Replace("{url}", url)
                              .Replace("{action}", action)
                              .Replace("{minutes}", minutes)
                              .Replace("%7Burl%7D", url);

                var NotifyIds = CurrentDatabase.StaffPeopleForOrg(oorg.OrganizationId);

                if (person != null)
                {
                    CurrentDatabase.Email(NotifyIds[0].FromEmail, person, subject, msg); // send confirmation
                }
                else //send email to no db person
                {
                    var from = new MailAddress(NotifyIds[0].EmailAddress ?? NotifyIds[0].EmailAddress2, NotifyIds[0].Name);
                    CurrentDatabase.SendEmail(from, subject, msg, Util.ToMailAddressList(gs.NoDbEmail), gs.Id);
                }

                return(Message($"Thank you, {personPreferredName}we just sent an email to {Util.ObscureEmail(personEmailAddress)} with your link..."));
            }
            catch (Exception ex)
            {
                DbUtil.LogActivity($"{sendlinkSTR}{confirmSTR}Error: {ex.Message}", li.oid, li.pid);
                return(Message(ex.Message));
            }
        }