Exemple #1
0
        protected void notifySubscribers(LiftContext ctx)
        {
            Organization org = Organization.Current;

            OrgEmail oe = new OrgEmail();

            oe.organization_id.Value = org.id.Value;
            oe = oe.doSingleObjectQuery <OrgEmail>("select");

            Request r = new Request();

            r.id.Value = ctx.getInt("request_id");
            List <Request> rlist = r.doQuery <Request>("get_most_recent_update");


            StringBuilder body = new StringBuilder();

            string title = string.Empty;

            foreach (Request u in rlist)
            {
                if (title.Length == 0)
                {
                    title = u.title.Value;
                }

                body.Append("From: ");
                body.Append(u.from.Value);
                body.Append(" (");
                body.Append(u.from_email.Value);
                body.Append(")");
                // body.Append(u.getDateTime("post_date").ToString("G"));  // times are in utc - needs to be converted to subscriber tz
                body.Append("\r\n\r\n");
                body.Append(u.description.Value);
                body.Append("\r\n\r\n");
            }

            Email e = new Email();

            e.from = org.getFromEmail();
            e.Body = body.ToString();

            e.subject = "Update: " + title;

            Subscription s = new Subscription();

            s.request_id.Value = ctx.getInt("request_id");
            DataSet subsribers = s.doQuery("get_subscribers");

            if (DatabasePersist.hasData(subsribers))
            {
                foreach (DataRow subscriber in subsribers.Tables[0].Rows)
                {
                    e.clearRecipients();
                    e.addTo(subscriber["email"].ToString());
                    e.send();
                }
            }
        }
Exemple #2
0
        public void notifyAdjacent(int currentWallId, int userId, int dow, int tod, bool subscribe)
        {
            string header         = headerMsg;
            string recvMsg        = string.Empty;
            string giveMsg        = string.Empty;
            string subj           = string.Empty;
            string thisUserHeader = string.Empty;

            if (subscribe)
            {
                recvMsg        = recvWatchMsg;
                giveMsg        = giveWatchMsg;
                subj           = "New Watchman Notification";
                thisUserHeader = headerMsg;
            }
            else
            {
                recvMsg        = noLongerRecvWatchMsg;
                giveMsg        = noLongerGiveWatchMsg;
                subj           = "Watchman Change Notifcation";
                thisUserHeader = unsubscribeHeaderMsg;
            }


            OrgEmail oe = new OrgEmail();

            oe.organization_id.Value = Organization.Current.id.Value;
            oe = oe.doSingleObjectQuery <OrgEmail>("select");

            int prevDow = 0;
            int prevTod = 0;
            int nextDow = 0;
            int nextTod = 0;

            calcPrev(dow, tod, ref prevDow, ref prevTod);
            calcNext(dow, tod, ref nextDow, ref nextTod);

            Appt adj = new Appt();

            adj["wall_id"]  = currentWallId;
            adj["next_tod"] = nextTod;
            adj["next_dow"] = nextDow;
            adj["prev_tod"] = prevTod;
            adj["prev_dow"] = prevDow;

            adj["tzoffset"] = LiftTime.UserTzOffset;

            DataSet neighbors = adj.doQuery("get_adjacent");
            User    thisUser  = new User();

            thisUser.id.Value = userId;
            thisUser          = thisUser.doSingleObjectQuery <User>("getobject");

            User prior = null;
            User next  = null;

            if (DatabasePersist.hasData(neighbors))
            {
                foreach (DataRow neighbor in neighbors.Tables[0].Rows)
                {
                    string rel = neighbor["rel"].ToString();

                    if (rel == "before")
                    {
                        prior          = new User();
                        prior.id.Value = Convert.ToInt32(neighbor["user_id"]);
                        prior          = prior.doSingleObjectQuery <User>("getobject");
                    }

                    if (rel == "after")
                    {
                        next          = new User();
                        next.id.Value = Convert.ToInt32(neighbor["user_id"]);
                        next          = next.doSingleObjectQuery <User>("getobject");
                    }
                }
            }

            StringBuilder currentBody = new StringBuilder(thisUserHeader);

            replace(currentBody, "day_name", getDay(dow));
            replace(currentBody, "time", getTime(tod));

            if (prior != null)
            {
                StringBuilder priorBody = new StringBuilder(header);
                replace(priorBody, "day_name", getDay(prevDow));
                replace(priorBody, "time", getTime(prevTod));

                priorBody.Append(giveMsg);
                replace(priorBody, "next_first_name", thisUser.first_name.Value);
                replace(priorBody, "next_last_name", thisUser.last_name.Value);
                replace(priorBody, "next_email", thisUser.email.Value);
                replace(priorBody, "next_phone", thisUser.phone.Value);

                currentBody.Append(recvMsg);
                replace(currentBody, "prev_first_name", prior.first_name.Value);
                replace(currentBody, "prev_last_name", prior.last_name.Value);
                replace(currentBody, "prev_email", prior.email.Value);
                replace(currentBody, "prev_phone", prior.phone.Value);

                priorBody.Append(footerMsg);

                Email priorEmail = new Email();
                priorEmail.subject = subj;
                priorEmail.Body    = priorBody.ToString();
                priorEmail.addTo(prior.email.Value);
                priorEmail.from = Organization.Current.getFromEmail();
                priorEmail.send();
            }

            if (next != null)
            {
                StringBuilder nextBody = new StringBuilder(header);
                replace(nextBody, "day_name", getDay(nextDow));
                replace(nextBody, "time", getTime(nextTod));

                nextBody.Append(recvMsg);
                replace(nextBody, "prev_first_name", thisUser.first_name.Value);
                replace(nextBody, "prev_last_name", thisUser.last_name.Value);
                replace(nextBody, "prev_email", thisUser.email.Value);
                replace(nextBody, "prev_phone", thisUser.phone.Value);

                currentBody.Append(giveMsg);
                replace(currentBody, "next_first_name", next.first_name.Value);
                replace(currentBody, "next_last_name", next.last_name.Value);
                replace(currentBody, "next_email", next.email.Value);
                replace(currentBody, "next_phone", next.phone.Value);

                nextBody.Append(footerMsg);

                Email nextEmail = new Email();
                nextEmail.subject = subj;
                nextEmail.Body    = nextBody.ToString();
                nextEmail.addTo(next.email.Value);
                nextEmail.from = Organization.Current.getFromEmail();
                nextEmail.send();
            }

            currentBody.Append(footerMsg);

            Email thisEmail = new Email();

            thisEmail.subject = subj;
            thisEmail.Body    = currentBody.ToString();
            thisEmail.addTo(thisUser.email.Value);
            thisEmail.from = Organization.Current.getFromEmail();
            thisEmail.send();
        }