Пример #1
0
        public void UpdateCommitments()
        {
            var commitments = (from m in Meetings()
                               where m.iscommitted
                               select m.MeetingDate).ToList();

            if (Commit == null)
            {
                Commit = new DateTime[] { }
            }
            ;

            var decommits = from currcommit in commitments
                            join newcommit in Commit on currcommit equals newcommit into j
                            from newcommit in j.DefaultIfEmpty(DateTime.MinValue)
                            where newcommit == DateTime.MinValue
                            select currcommit;

            var commits = from newcommit in Commit
                          join currcommit in commitments on newcommit equals currcommit into j
                          from currcommit in j.DefaultIfEmpty(DateTime.MinValue)
                          where currcommit == DateTime.MinValue
                          select newcommit;

            foreach (var currcommit in decommits)
            {
                Attend.MarkRegistered(DbUtil.Db, OrgId, PeopleId, currcommit, AttendCommitmentCode.Regrets);
            }
            foreach (var newcommit in commits)
            {
                Attend.MarkRegistered(DbUtil.Db, OrgId, PeopleId, newcommit, AttendCommitmentCode.Attending);
            }
            OrganizationMember.InsertOrgMembers(DbUtil.Db,
                                                OrgId, PeopleId, MemberTypeCode.Member, DateTime.Now, null, false);
        }
Пример #2
0
        private ReturnResult AddRegistered(int id, int origin)
        {
            var meeting = DbUtil.Db.Meetings.SingleOrDefault(me => me.MeetingId == id);

            if (meeting != null)
            {
                foreach (var p in PendingList)
                {
                    var isnew = p.IsNew;
                    AddPerson(p, PendingList, origin, EntryPointId);
                    if (isnew)
                    {
                        p.Person.CampusId = meeting.Organization.CampusId;
                    }

                    if (!p.PeopleId.HasValue)
                    {
                        continue;
                    }

                    Attend.MarkRegistered(DbUtil.Db, p.PeopleId.Value, id, 1);
                    DbUtil.LogActivity("AddRegistered " + meeting.MeetingDate.FormatDateTm(), meeting.OrganizationId, p.PeopleId);
                }
                DbUtil.Db.SubmitChanges();
                DbUtil.Db.UpdateMeetingCounters(meeting.MeetingId);
            }
            return(new ReturnResult {
                close = true, how = "addselected", from = AddContext
            });
        }
Пример #3
0
 private string MarkAttendingIntention(int code)
 {
     if (person == null)
     {
         return(GetNoPersonMessage());
     }
     try
     {
         row.Args = $"{{ \"MeetingId\": \"{action.MeetingId}\"}}";
         if (action.MeetingId == null)
         {
             throw new Exception("meetingid null");
         }
         meeting = CurrentDatabase.Meetings.FirstOrDefault(mm => mm.MeetingId == action.MeetingId);
         if (meeting == null)
         {
             throw new Exception($"meetingid {action.MeetingId} not found");
         }
         organization = CurrentDatabase.LoadOrganizationById(meeting.OrganizationId);
         Attend.MarkRegistered(CurrentDatabase, person.PeopleId, meeting.MeetingId, code);
         markedas = code == AttendCommitmentCode.Attending ? "Attending" : "Regrets";
     }
     catch (Exception e)
     {
         return(GetError($"No Meeting on action {action.Action}, {e.Message}"));
     }
     return(GetActionReplyMessage());
 }
Пример #4
0
        public void ProcessReply(string ans)
        {
            var dt = new DateTime(ticks);
            var i  = (from rr in CurrentDatabase.SubRequests
                      where rr.AttendId == attend.AttendId
                      where rr.RequestorId == person.PeopleId
                      where rr.Requested == dt
                      where rr.SubstituteId == sid
                      select rr).Single();

            if (attend.Commitment == AttendCommitmentCode.SubFound || attend.SubRequests.Any(ss => ss.CanSub == true))
            {
                DisplayMessage = "This substitute request has already been covered. Thank you so much for responding.";
                Log("Covered", i.Requested, i.SubstituteId);
                return;
            }
            i.Responded = DateTime.Now;
            if (ans != "yes")
            {
                DisplayMessage = "Thank you for responding";
                i.CanSub       = false;
                Log("Regrets", i.Requested, i.SubstituteId);
                CurrentDatabase.SubmitChanges();
                return;
            }
            i.CanSub = true;
            Attend.MarkRegistered(CurrentDatabase, i.Substitute.PeopleId, attend.MeetingId, AttendCommitmentCode.Substitute);
            attend.Commitment = AttendCommitmentCode.SubFound;
            Log("Claimed", i.Requested, i.SubstituteId);
            CurrentDatabase.SubmitChanges();

            message = CurrentDatabase.ContentHtml("VolunteerSubConfirm", Resource1.VolSubModel_VolunteerSubConfirm);

            var body = message
                       .Replace("{substitute}", i.Substitute.Name)
                       .Replace("{requestor}", i.Requestor.Name)
                       .Replace("{org}", org.OrganizationName)
                       .Replace("{meetingdate}", $"{attend.MeetingDate:MMM d, yyyy}")
                       .Replace("{meetingtime}", $"{attend.MeetingDate:h:mm tt}");

            // on screen message
            DisplayMessage = $"<p>You have been sent the following email at {Util.ObscureEmail(i.Substitute.EmailAddress)}.</p>\n" + body;

            // email confirmation
            CurrentDatabase.Email(i.Requestor.FromEmail, i.Substitute,
                                  "Volunteer Substitute Commitment for " + org.OrganizationName, body);

            // notify requestor and org notifyids
            var list = CurrentDatabase.PeopleFromPidString(org.NotifyIds).ToList();

            list.Insert(0, i.Requestor);
            CurrentDatabase.Email(i.Substitute.FromEmail, list,
                                  "Volunteer Substitute Commitment for " + org.OrganizationName,
                                  $@"
<p>The following email was sent to {i.Substitute.Name}.</p>
<blockquote>
{body}
</blockquote>");
        }
Пример #5
0
        public void ProcessReply(string ans)
        {
            if (attend.SubRequests.Any(ss => ss.CanSub == true))
            {
                DisplayMessage = "This substitute request has already been covered. Thank you so much for responding.";
                return;
            }
            var dt = new DateTime(ticks);
            var r  = (from rr in Db.SubRequests
                      where rr.AttendId == attend.AttendId
                      where rr.RequestorId == person.PeopleId
                      where rr.Requested == dt
                      where rr.SubstituteId == sid
                      select rr).Single();

            r.Responded = DateTime.Now;
            if (ans != "yes")
            {
                DisplayMessage = "Thank you for responding";
                r.CanSub       = false;
                Db.SubmitChanges();
                return;
            }
            r.CanSub = true;
            Attend.MarkRegistered(Db, r.Substitute.PeopleId, attend.MeetingId, CmsData.Codes.AttendCommitmentCode.Substitute);
            attend.Commitment = CmsData.Codes.AttendCommitmentCode.SubFound;
            Db.SubmitChanges();
            var body = @"
<p>{0},</p>
<p>Thank you so much.</p>
<p>You are now assigned to cover for {1}<br />
in the {2}<br />
on {3:MMM d, yyyy} at {3:t}.
See you there!</p>".Fmt(r.Substitute.Name, r.Requestor.Name,
                        org.OrganizationName, attend.MeetingDate);

            // on screen message
            DisplayMessage = "<p>You have been sent the following email at {0}.</p>\n"
                             .Fmt(Util.ObscureEmail(r.Substitute.EmailAddress)) + body;

            // email confirmation
            Db.Email(r.Requestor.FromEmail, r.Substitute,
                     "Volunteer Substitute Committment for " + org.OrganizationName, body);

            // notify requestor and org notifyids
            var list = Db.PeopleFromPidString(org.NotifyIds).ToList();

            list.Insert(0, r.Requestor);
            Db.Email(r.Substitute.FromEmail, list,
                     "Volunteer Substitute Committment for " + org.OrganizationName,
                     @"
<p>The following email was sent to {0}.</p>
<blockquote>
{1}
</blockquote>".Fmt(r.Substitute.Name, body));
        }
Пример #6
0
 public ActionResult MarkRegistered(int PeopleId, int MeetingId, int?CommitId)
 {
     try
     {
         Attend.MarkRegistered(DbUtil.Db, PeopleId, MeetingId, CommitId);
     }
     catch (Exception ex)
     {
         return(Content(ex.Message));
     }
     return(new EmptyResult());
 }
Пример #7
0
        public ActionResult MarkRegistered(int meetingid, int peopleid, int?CommitId)
        {
            var ret = AuthenticateDeveloper();

            if (ret.StartsWith("!"))
            {
                return(Content(ret.Substring(1)));
            }
            DbUtil.LogActivity($"APIMeeting MarkRegistered {meetingid}, {peopleid}");
            Attend.MarkRegistered(DbUtil.Db, peopleid, meetingid, CommitId);
            return(Content("ok"));
        }
Пример #8
0
        public ContentResult EditCommitment(string id, string value)
        {
            var a = id.Substring(1).Split('_').Select(vv => vv.ToInt()).ToArray();
            var c = value.ToInt2();

            if (c == 99)
            {
                c = null;
            }
            Attend.MarkRegistered(DbUtil.Db, a[1], a[0], c);
            var desc = CmsData.Codes.AttendCommitmentCode.Lookup(c ?? 99);

            return(Content(desc));
        }
Пример #9
0
        public void UpdateCommitments()
        {
            var commitments = (from m in Meetings()
                               where m.iscommitted
                               select m.MeetingDate).ToList();

            if (Commit == null)
            {
                Commit = new DateTime[] { };
            }

            var decommits = from currcommit in commitments
                            join newcommit in Commit on currcommit equals newcommit into j
                            from newcommit in j.DefaultIfEmpty(DateTime.MinValue)
                            where newcommit == DateTime.MinValue
                            select currcommit;

            var commits = from newcommit in Commit
                          join currcommit in commitments on newcommit equals currcommit into j
                          from currcommit in j.DefaultIfEmpty(DateTime.MinValue)
                          where currcommit == DateTime.MinValue
                          select newcommit;

            int?mid = null;

            foreach (var currcommit in decommits)
            {
                mid = Attend.MarkRegistered(DbUtil.Db, OrgId, PeopleId, currcommit, AttendCommitmentCode.Regrets);
            }

            foreach (var newcommit in commits)
            {
                mid = Attend.MarkRegistered(DbUtil.Db, OrgId, PeopleId, newcommit, AttendCommitmentCode.Attending);
            }

            if (mid.HasValue)
            {
                var slots = FetchSlots();
                Meeting.AddEditExtraData(DbUtil.Db, mid.Value, "Description", slots.First().Description);
            }
            var om = DbUtil.Db.OrganizationMembers.SingleOrDefault(mm => mm.PeopleId == PeopleId && mm.OrganizationId == OrgId);

            if (om == null)
            {
                OrganizationMember.InsertOrgMembers(DbUtil.Db,
                                                    OrgId, PeopleId, MemberTypeCode.Member, DateTime.Now, null, false);
            }
        }
Пример #10
0
 public void AddToSmallGroup(CMSDataContext Db, OrganizationMember om, PythonModel pe)
 {
     if (om == null)
     {
         return;
     }
     if (pe != null)
     {
         pe.instance.AddToSmallGroup(SmallGroup, om);
     }
     om.AddToGroup(Db, SmallGroup);
     if (MeetingTime.HasValue)
     {
         Attend.MarkRegistered(Db, om.OrganizationId, om.PeopleId, MeetingTime.Value, 1);
     }
 }
Пример #11
0
        public ContentResult EditCommitment(string id, string value)
        {
            var a = id.Substring(1).Split('_').Select(vv => vv.ToInt()).ToArray();
            var c = value.ToInt2();

            if (c == 99)
            {
                c = null;
            }

            Attend.MarkRegistered(CurrentDatabase, a[1], a[0], c);
            var desc = AttendCommitmentCode.Lookup(c ?? 99);

            DbUtil.LogActivity($"EditCommitment {desc} id={id}");
            return(Content(desc));
        }
Пример #12
0
 private JsonResult AddRegistered(int id, SearchAddModel m, int origin)
 {
     if (id > 0)
     {
         var meeting = DbUtil.Db.Meetings.SingleOrDefault(me => me.MeetingId == id);
         foreach (var p in m.List)
         {
             var isnew = p.IsNew;
             AddPerson(p, m.List, origin, m.EntryPointId);
             if (isnew)
             {
                 p.person.CampusId = meeting.Organization.CampusId;
             }
             Attend.MarkRegistered(DbUtil.Db, p.PeopleId.Value, id, 1);
         }
         DbUtil.Db.SubmitChanges();
         DbUtil.Db.UpdateMeetingCounters(meeting.MeetingId);
     }
     return(Json(new { close = true, how = "addselected" }));
 }
Пример #13
0
        public ActionResult RsvpLinkSg(string id, string message, bool?confirm)
        {
            if (!id.HasValue())
            {
                return(Content("bad link"));
            }

            var guid = id.ToGuid();

            if (guid == null)
            {
                return(Content("invalid link"));
            }
            var ot = DbUtil.Db.OneTimeLinks.SingleOrDefault(oo => oo.Id == guid.Value);

            if (ot == null)
            {
                return(Content("invalid link"));
            }
            if (ot.Used)
            {
                return(Content("link used"));
            }
            if (ot.Expires.HasValue && ot.Expires < DateTime.Now)
            {
                return(Content("link expired"));
            }
            var a          = ot.Querystring.SplitStr(",", 4);
            var meetingid  = a[0].ToInt();
            var pid        = a[1].ToInt();
            var emailid    = a[2].ToInt();
            var smallgroup = a[3];
            var q          = (from pp in DbUtil.Db.People
                              where pp.PeopleId == pid
                              let meeting = DbUtil.Db.Meetings.SingleOrDefault(mm => mm.MeetingId == meetingid)
                                            let org = meeting.Organization
                                                      select new { p = pp, org, meeting }).Single();

            if (q.org.RegistrationClosed == true || q.org.OrganizationStatusId == OrgStatusCode.Inactive)
            {
                return(Content("sorry, registration has been closed"));
            }

            if (q.org.RegistrationTypeId == RegistrationTypeCode.None)
            {
                return(Content("rsvp is no longer available"));
            }

            if (q.org.Limit <= q.meeting.Attends.Count(aa => aa.Commitment == 1))
            {
                return(Content("sorry, maximum limit has been reached"));
            }
            var omb = OrganizationMember.InsertOrgMembers(DbUtil.Db,
                                                          q.meeting.OrganizationId, pid, MemberTypeCode.Member, DateTime.Now, null, false);

            if (smallgroup.HasValue())
            {
                omb.AddToGroup(DbUtil.Db, smallgroup);
            }
            omb.AddToGroup(DbUtil.Db, "emailid:" + emailid);


            ot.Used = true;
            DbUtil.Db.SubmitChanges();
            Attend.MarkRegistered(DbUtil.Db, pid, meetingid, 1);
            DbUtil.LogActivity("Rsvplink: {0}".Fmt(q.org.OrganizationName));
            var setting = new Settings(q.org.RegSetting, DbUtil.Db, q.meeting.OrganizationId);

            if (confirm == true)
            {
                var subject = Util.PickFirst(setting.Subject, "no subject");
                var msg     = Util.PickFirst(setting.Body, "no message");
                msg = CmsData.API.APIOrganization.MessageReplacements(DbUtil.Db, q.p, q.org.DivisionName, q.org.OrganizationName, q.org.Location, msg);
                msg = msg.Replace("{details}", q.meeting.MeetingDate.ToString2("f"));
                var NotifyIds = DbUtil.Db.StaffPeopleForOrg(q.org.OrganizationId);

                DbUtil.Db.Email(NotifyIds[0].FromEmail, q.p, subject, msg); // send confirmation
                DbUtil.Db.Email(q.p.FromEmail, NotifyIds,
                                q.org.OrganizationName,
                                "{0} has registered for {1}<br>{2}".Fmt(q.p.Name, q.org.OrganizationName, q.meeting.MeetingDate.ToString2("f")));
            }
            return(Content(message));
        }
Пример #14
0
        public void ProcessReply(string ans)
        {
            var dt = new DateTime(ticks);

            var i = (from rr in Db.VolRequests
                     where rr.MeetingId == meeting.MeetingId
                     where rr.RequestorId == person.PeopleId
                     where rr.Requested == dt
                     where rr.VolunteerId == vid
                     let commits = (from a in rr.Meeting.Attends
                                    where AttendCommitmentCode.committed.Contains(a.Commitment ?? 0)
                                    select a).Count()
                                   let needed = (from e in rr.Meeting.MeetingExtras
                                                 where e.Field == "TotalVolunteersNeeded"
                                                 select e.Data).SingleOrDefault()
                                                select new
            {
                volunteer = rr.Volunteer,
                r = rr,
                commits,
                needed
            }).Single();

            if (i.commits >= i.needed.ToInt())
            {
                DisplayMessage = "This volunteer request has already been covered. Thank you so much for responding.";
                return;
            }
            i.r.Responded = DateTime.Now;
            if (ans != "yes")
            {
                DisplayMessage = "Thank you for responding";
                i.r.CanVol     = false;
                Db.SubmitChanges();
                return;
            }
            i.r.CanVol = true;
            Attend.MarkRegistered(Db, i.r.VolunteerId, meeting.MeetingId, AttendCommitmentCode.Attending);
            Db.SubmitChanges();
            var body = $@"
<p>{i.volunteer.Name},</p>
<p>Thank you so much.</p>
<p>You are now assigned to volunteer on {meeting.MeetingDate:MMM d, yyyy} at {meeting.MeetingDate:t}.
in {org.OrganizationName}<br />
<p><a id=""{org.OrganizationId}"" href=""http://registerlink"">Click here</a> to manage your commitments.</p>
<p>See you there!</p>";

            Db.Email(person.FromEmail, i.volunteer, "Thank you for responding and serving", body);

            // on screen message
            DisplayMessage = $@"<p>You have been sent the following email at {Util.ObscureEmail(i.volunteer.EmailAddress)}.</p>
<p>{i.volunteer.Name},</p>
<p>Thank you so much.</p>
<p>You are now assigned to volunteer on {meeting.MeetingDate:MMM d, yyyy} at {meeting.MeetingDate:t}.
in {org.OrganizationName}<br />
<p><u>Click here</u> to manage your commitments.</p>
<p>See you there!</p>";

            // notify requestor and org notifyids
            var list = Db.PeopleFromPidString(org.NotifyIds).ToList();

            list.Insert(0, person);
            Db.Email(i.volunteer.FromEmail, list,
                     "Volunteer Committment for " + org.OrganizationName,
                     $@"
<p>The following email was sent to {i.volunteer.Name}.</p>
<blockquote>
{body}
</blockquote>");
        }
Пример #15
0
        public ActionResult RsvpLinkSg(string id, string message, bool?confirm, FormCollection formCollection, bool regrets = false)
        {
            var li = new LinkInfo(rsvplinkSTR, landingSTR, id, false);

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

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

                var meetingid  = li.a[0].ToInt();
                var emailid    = li.a[2].ToInt();
                var smallgroup = li.a[3];
                if (meetingid == 0 && li.a[0].EndsWith(".next"))
                {
                    var orgid    = li.a[0].Split('.')[0].ToInt();
                    var nextmeet = (from mm in DbUtil.Db.Meetings
                                    where mm.OrganizationId == orgid
                                    where mm.MeetingDate > DateTime.Now
                                    orderby mm.MeetingDate
                                    select mm).FirstOrDefault();
                    if (nextmeet == null)
                    {
                        return(Message("no meeting"));
                    }
                    meetingid = nextmeet.MeetingId;
                }
                var q = (from pp in DbUtil.Db.People
                         where pp.PeopleId == li.pid
                         let meeting = DbUtil.Db.Meetings.SingleOrDefault(mm => mm.MeetingId == meetingid)
                                       let org = meeting.Organization
                                                 select new { p = pp, org, meeting }).Single();

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

                if (q.org.RegistrationTypeId == RegistrationTypeCode.None)
                {
                    throw new Exception("rsvp is no longer available");
                }

                if (q.org.Limit <= q.meeting.Attends.Count(aa => aa.Commitment == 1))
                {
                    throw new Exception("sorry, maximum limit has been reached");
                }
                var omb = OrganizationMember.Load(DbUtil.Db, li.pid.Value, q.meeting.OrganizationId) ??
                          OrganizationMember.InsertOrgMembers(DbUtil.Db,
                                                              q.meeting.OrganizationId, li.pid.Value, MemberTypeCode.Member, DateTime.Now, null, false);
                if (smallgroup.HasValue())
                {
                    omb.AddToGroup(DbUtil.Db, smallgroup);
                }

                li.ot.Used = true;
                DbUtil.Db.SubmitChanges();
                Attend.MarkRegistered(DbUtil.Db, li.pid.Value, meetingid, regrets ? AttendCommitmentCode.Regrets : AttendCommitmentCode.Attending);
                DbUtil.LogActivity($"{rsvplinkSTR}{confirmSTR}: {regrets}", q.org.OrganizationId, li.pid);
                var setting = DbUtil.Db.CreateRegistrationSettings(q.meeting.OrganizationId);

                if (confirm == true)
                {
                    var subject = Util.PickFirst(setting.Subject, "no subject");
                    var msg     = Util.PickFirst(setting.Body, "no message");
                    msg = APIOrganization.MessageReplacements(DbUtil.Db, q.p, q.org.DivisionName, q.org.OrganizationId, q.org.OrganizationName, q.org.Location, msg);
                    msg = msg.Replace("{details}", q.meeting.MeetingDate.ToString2("f"));
                    var NotifyIds = DbUtil.Db.StaffPeopleForOrg(q.org.OrganizationId);

                    DbUtil.Db.Email(NotifyIds[0].FromEmail, q.p, subject, msg); // send confirmation
                    DbUtil.Db.Email(q.p.FromEmail, NotifyIds,
                                    q.org.OrganizationName,
                                    $"{q.p.Name} has registered for {q.org.OrganizationName}<br>{q.meeting.MeetingDate.ToString2("f")}");
                }
            }
            catch (Exception ex)
            {
                DbUtil.LogActivity($"{rsvplinkSTR}{confirmSTR}Error: {regrets}", peopleid: li.pid);
                return(Message(ex.Message));
            }
            return(Message(message));
        }
        public void ApplyDragDrop(
            string target,
            int?week,
            DateTime?time,
            DragDropInfo i)
        {
            List <int> volids = null;

            switch (i.source)
            {
            case "nocommits":
                volids = (from p in Volunteers()
                          where p.commits == 0
                          select p.PeopleId).ToList();
                break;

            case "commits":
                volids = (from p in Volunteers()
                          where p.commits > 0
                          select p.PeopleId).ToList();
                break;

            case "all":
                volids = (from p in Volunteers()
                          select p.PeopleId).ToList();
                break;

            case "registered":
            case "person":
                volids = new List <int>()
                {
                    i.pid.ToInt()
                };
                break;

            default:
                return;
            }

            if (target == "week")
            {
                var slots = (from s in FetchSlots()
                             where s.Time.TimeOfDay == time.Value.TimeOfDay
                             where s.Week == week || week == 0
                             select s).ToList();
                foreach (var PeopleId in volids)
                {
                    if (i.source == "registered")
                    {
                        DropFromAll(PeopleId);
                    }
                    foreach (var s in slots)
                    {
                        Attend.MarkRegistered(DbUtil.Db, OrgId, PeopleId, s.Time,
                                              AttendCommitmentCode.Attending, AvoidRegrets: true);
                    }
                }
            }
            else if (target == "meeting")
            {
                foreach (var PeopleId in volids)
                {
                    if (i.source == "registered")
                    {
                        DropFromMeeting(i.mid.Value, PeopleId);
                    }
                    Attend.MarkRegistered(DbUtil.Db, OrgId, PeopleId, time.Value,
                                          AttendCommitmentCode.Attending, AvoidRegrets: true);
                }
            }
            else if (target == "clear")
            {
                foreach (var PeopleId in volids)
                {
                    if (i.source == "registered")
                    {
                        DropFromMeeting(i.mid.Value, PeopleId);
                    }
                    else
                    {
                        DropFromAll(PeopleId);
                    }
                }
            }
        }