public MpOpportunity GetOpportunityById(int opportunityId, string token)
        {
            var opp         = _ministryPlatformService.GetRecordDict(_opportunityPage, opportunityId, token);
            var shiftStart  = opp.ToNullableTimeSpan("Shift_Start");
            var shiftEnd    = opp.ToNullableTimeSpan("Shift_End");
            var opportunity = new MpOpportunity
            {
                OpportunityId    = opportunityId,
                OpportunityName  = opp.ToString("Opportunity_Title"),
                EventType        = opp.ToString("Event_Type_ID_Text"),
                EventTypeId      = opp.ToInt("Event_Type_ID"),
                RoleTitle        = opp.ToString("Group_Role_ID_Text"),
                MaximumNeeded    = opp.ToNullableInt("Maximum_Needed"),
                MinimumNeeded    = opp.ToNullableInt("Minimum_Needed"),
                GroupContactId   = opp.ToInt("Contact_Person"),
                GroupContactName = opp.ToString("Contact_Person_Text"),
                GroupName        = opp.ToString("Add_to_Group_Text"),
                GroupId          = opp.ToInt("Add_to_Group"),
                ShiftStart       = shiftStart,
                ShiftEnd         = shiftEnd,
                Room             = opp.ToString("Room")
            };

            return(opportunity);
        }
Example #2
0
        private Dictionary <string, object> SetupMergeData(int contactId,
                                                           int opportunityId,
                                                           MpOpportunity previousOpportunity,
                                                           MpOpportunity currentOpportunity,
                                                           DateTime startDate,
                                                           DateTime endDate,
                                                           MpMyContact groupContact,
                                                           String htmlTable)
        {
            MpMyContact volunteer = _contactService.GetContactById(contactId);

            return(new Dictionary <string, object>
            {
                { "Opportunity_Name", opportunityId == 0 ? "Not Available" : currentOpportunity.OpportunityName },
                { "Start_Date", startDate.ToShortDateString() },
                { "End_Date", endDate.ToShortDateString() },
                { "Shift_Start", currentOpportunity.ShiftStart.FormatAsString() ?? string.Empty },
                { "Shift_End", currentOpportunity.ShiftEnd.FormatAsString() ?? string.Empty },
                { "Room", currentOpportunity.Room ?? string.Empty },
                { "Group_Contact", groupContact.Nickname + " " + groupContact.Last_Name },
                { "Group_Name", currentOpportunity.GroupName },
                {
                    "Previous_Opportunity_Name",
                    previousOpportunity != null ? previousOpportunity.OpportunityName : @"Not Available"
                },
                { "Volunteer_Name", volunteer.Nickname + " " + volunteer.Last_Name },
                { "Html_Table", htmlTable }
            });
        }
Example #3
0
        public List <int> SaveServeRsvp(string token, SaveRsvpDto dto)
        {
            List <MailRow> mailRows = new List <MailRow>();

            var templateId   = GetRsvpTemplate(dto.SignUp);
            var opportunity  = GetOpportunity(token, dto.OpportunityId, dto.OpportunityIds);
            var groupContact = _contactService.GetContactById(opportunity.GroupContactId);

            var           toContact           = _contactService.GetContactById(dto.ContactId);
            MpOpportunity previousOpportunity = null;

            try
            {
                var fromDate      = GetTimeStamp(opportunity.ShiftStart);
                var toDate        = GetTimeStamp(opportunity.ShiftEnd);
                var updatedEvents = GetUpdatedOpportunities(token,
                                                            dto,
                                                            (participant, e) =>
                {
                    mailRows.Add(new MailRow()
                    {
                        EventDate       = e.EventStartDate.ToShortDateString(),
                        Location        = opportunity.Room,
                        OpportunityName = opportunity.OpportunityName,
                        ShiftTime       = fromDate + " - " + toDate
                    });
                    var response        = CreateRsvp(token, dto.OpportunityId, dto.OpportunityIds, dto.SignUp, participant, e, groupContact);
                    previousOpportunity = PreviousOpportunity(response, previousOpportunity);
                    templateId          = GetTemplateId(templateId, response);
                    return(true);
                });
                var table     = SetupHTMLTable(mailRows).Build();
                var mergeData = SetupMergeData(dto.ContactId,
                                               dto.OpportunityId,
                                               previousOpportunity,
                                               opportunity,
                                               dto.StartDateUnix.FromUnixTime(),
                                               dto.EndDateUnix.FromUnixTime(),
                                               groupContact,
                                               table);

                var communication = SetupCommunication(templateId, groupContact, toContact, mergeData);
                _communicationService.SendMessage(communication);
                return(updatedEvents);
            }
            catch (Exception e)
            {
                //var communication = SetupCommunication(templateId, groupContact, toContact);
                var table         = SetupHTMLTable(mailRows).Build();
                var communication = SetupCommunication(AppSetting("SignupToServeFailedMessage"),
                                                       groupContact,
                                                       toContact,
                                                       new Dictionary <string, object>
                {
                    { "Html_Table", table }
                });
                _communicationService.SendMessage(communication);
                return(new List <int>());
            }
        }
Example #4
0
        private Dictionary <string, object> HandleNoRsvp(MpParticipant participant,
                                                         MpEvent e,
                                                         List <int> opportunityIds,
                                                         string token,
                                                         MpMyContact groupLeader)
        {
            int           templateId;
            MpOpportunity previousOpportunity = null;

            try
            {
                templateId = AppSetting("RsvpNoTemplate");
                //opportunityId = opportunityIds.First();
                _eventService.UnregisterParticipantForEvent(participant.ParticipantId, e.EventId);
            }
            catch (ApplicationException ex)
            {
                logger.Debug(ex.Message + ": There is no need to remove the event participant because there is not one.");
                templateId = AppSetting("RsvpNoTemplate");
            }

            // Responding no means that we are saying no to all opportunities for this group for this event
            foreach (var oid in opportunityIds)
            {
                var comments   = string.Empty; //anything of value to put in comments?
                var updatedOpp = _opportunityService.RespondToOpportunity(participant.ParticipantId,
                                                                          oid,
                                                                          comments,
                                                                          e.EventId,
                                                                          false);
                if (updatedOpp > 0)
                {
                    previousOpportunity = _opportunityService.GetOpportunityById(oid, token);
                }
            }

            if (previousOpportunity != null)
            {
                var emailName            = participant.DisplayName;
                var emailEmail           = participant.EmailAddress;
                var emailTeamName        = previousOpportunity.GroupName;
                var emailOpportunityName = previousOpportunity.OpportunityName;
                var emailEventDateTime   = e.EventStartDate.ToString();

                SendCancellationMessage(groupLeader, emailName, emailEmail, emailTeamName, emailOpportunityName, emailEventDateTime);
            }

            return(new Dictionary <string, object>()
            {
                { "templateId", templateId },
                { "previousOpportunity", previousOpportunity },
                { "rsvp", false }
            });
        }
Example #5
0
        private Dictionary <string, object> HandleYesRsvp(MpParticipant participant,
                                                          MpEvent e,
                                                          int opportunityId,
                                                          IReadOnlyCollection <int> opportunityIds,
                                                          String token)
        {
            var           templateId          = AppSetting("RsvpYesTemplate");
            var           deletedRSVPS        = new List <int>();
            MpOpportunity previousOpportunity = null;

            var opportunity = _opportunityService.GetOpportunityById(opportunityId, token);

            //Try to register this user for the event
            _eventService.RegisterParticipantForEvent(participant.ParticipantId, e.EventId, opportunity.GroupId);

            // Make sure we are only rsvping for 1 opportunity by removing all existing responses
            deletedRSVPS.AddRange(from oid in opportunityIds
                                  let deletedResponse =
                                      _opportunityService.DeleteResponseToOpportunities(participant.ParticipantId, oid, e.EventId)
                                      where deletedResponse != 0
                                      select oid);

            if (deletedRSVPS.Count > 0)
            {
                templateId = AppSetting("RsvpChangeTemplate");
                if (opportunityIds.Count != deletedRSVPS.Count)
                {
                    //Changed yes to yes
                    //prevOppId = deletedRSVPS.First();
                    previousOpportunity = _opportunityService.GetOpportunityById(deletedRSVPS.First(), token);
                }
            }
            var comments = string.Empty; //anything of value to put in comments?

            _opportunityService.RespondToOpportunity(participant.ParticipantId,
                                                     opportunityId,
                                                     comments,
                                                     e.EventId,
                                                     true);
            return(new Dictionary <string, object>()
            {
                { "templateId", templateId },
                { "previousOpportunity", previousOpportunity },
                { "rsvp", true }
            });
        }
Example #6
0
 private static MpOpportunity PreviousOpportunity(Dictionary <string, object> response, MpOpportunity previousOpportunity)
 {
     if (response.ToNullableObject <MpOpportunity>("previousOpportunity") != null)
     {
         previousOpportunity = response.ToNullableObject <MpOpportunity>("previousOpportunity");
     }
     return(previousOpportunity);
 }