Beispiel #1
0
 private static string RecentAbsentsEmail(OrganizationController c, IEnumerable<RecentAbsent> list)
 {
     var q = from p in list
             orderby p.Consecutive, p.Name2
             select p;
     return ViewExtensions2.RenderPartialViewToString(c, "RecentAbsentsEmail", q);
 }
Beispiel #2
0
        public void SendNotices(OrganizationController c)
        {
            const int days = 36;

            var olist = FetchOrgs().Select(oo => oo.OrganizationId).ToList();

            var alist = (from p in DbUtil.Db.RecentAbsents(null, null, days)
                         where olist.Contains(p.OrganizationId)
                         select p).ToList();

            var mlist = (from r in DbUtil.Db.LastMeetings(null, DivisionId, days)
                         where olist.Contains(r.OrganizationId)
                         select r).ToList();

            var plist = from om in DbUtil.Db.OrganizationMembers
                        where olist.Contains(om.OrganizationId)
                        where om.MemberType.AttendanceTypeId == AttendTypeCode.Leader
                        let u =
                            om.Person.Users.FirstOrDefault(uu => uu.UserRoles.Any(r => r.Role.RoleName == "Access"))
                        where u != null
                        group om.OrganizationId by om.Person
                            into leaderlist
                        orderby leaderlist.Key.Name2
                            select leaderlist;

            var sb2 = new StringBuilder("Notices sent to:</br>\n<table>\n");
            foreach (var p in plist)
            {
                var sb = new StringBuilder("The following meetings are ready to be viewed:<br/>\n");
                var leader = p.Key;
                var orgids = p.Select(vv => vv).ToList();
                var meetings = mlist.Where(m => orgids.Contains(m.OrganizationId)).ToList();
                foreach (var m in meetings)
                {
                    string orgname = Organization.FormatOrgName(m.OrganizationName, m.LeaderName, m.Location);
                    sb.AppendFormat("<a href='{0}Meeting/Index/{1}'>{2} - {3}</a><br/>\n",
                                    DbUtil.Db.CmsHost, m.MeetingId, orgname, m.Lastmeeting.FormatDateTm());
                    sb2.AppendFormat("<tr><td>{0}</td><td>{1}</td><td>{2:g}</td></tr>\n",
                                     leader.Name, orgname, m.Lastmeeting.FormatDateTm());
                }
                foreach (var m in meetings)
                {
                    var absents = alist.Where(a => a.OrganizationId == m.OrganizationId);
                    sb.Append(RecentAbsentsEmail(c, absents));
                }
                DbUtil.Db.Email(DbUtil.Db.CurrentUser.Person.FromEmail, leader, null,
                                "Attendance reports are ready for viewing", sb.ToString(), false);
            }
            sb2.Append("</table>\n");
            DbUtil.Db.Email(DbUtil.Db.CurrentUser.Person.FromEmail, DbUtil.Db.CurrentUser.Person, null,
                            "Attendance emails sent", sb2.ToString(), false);
        }