Esempio n. 1
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 }
            });
        }
Esempio n. 2
0
        public void RegisterForEvent(EventRsvpDto eventDto, string token)
        {
            var defaultGroupRoleId = AppSetting("Group_Role_Default_ID");
            var today = DateTime.Today;

            try
            {
                var saved = eventDto.Participants.Select(participant =>
                {
                    var groupParticipantId = _groupParticipantService.Get(eventDto.GroupId, participant.ParticipantId);
                    if (groupParticipantId == 0)
                    {
                        groupParticipantId = _groupService.addParticipantToGroup(participant.ParticipantId,
                                                                                 eventDto.GroupId,
                                                                                 defaultGroupRoleId,
                                                                                 participant.ChildcareRequested,
                                                                                 today);
                    }

                    // validate that there is not a participant record before creating
                    var retVal =
                        Functions.IntegerReturnValue(
                            () =>
                            !_eventService.EventHasParticipant(eventDto.EventId, participant.ParticipantId)
                                    ? _eventService.RegisterParticipantForEvent(participant.ParticipantId, eventDto.EventId, eventDto.GroupId, groupParticipantId)
                                    : 1);

                    return(new RegisterEventObj()
                    {
                        EventId = eventDto.EventId,
                        ParticipantId = participant.ParticipantId,
                        RegisterResult = retVal,
                        ChildcareRequested = participant.ChildcareRequested
                    });
                }).ToList();

                SendRsvpMessage(saved, token);
            }
            catch (Exception e)
            {
                throw new ApplicationException("Unable to add event participant: " + e.Message);
            }
        }
Esempio n. 3
0
        public void addParticipantsToGroup(int groupId, List <ParticipantSignup> participants)
        {
            MpGroup group;

            try
            {
                group = _mpGroupService.getGroupDetails(groupId);
            }
            catch (Exception e)
            {
                var message = String.Format("Could not retrieve group details for group {0}: {1}", groupId, e.Message);
                _logger.Error(message, e);
                throw (new ApplicationException(message, e));
            }

            checkSpaceRemaining(participants, group);

            try
            {
                foreach (var participant in participants)
                {
                    int groupParticipantId;

                    var roleId = participant.groupRoleId ?? _groupRoleDefaultId;

                    var participantId = participant.particpantId.Value;
                    groupParticipantId = _mpGroupService.addParticipantToGroup(participantId,
                                                                               Convert.ToInt32(groupId),
                                                                               roleId,
                                                                               participant.childCareNeeded,
                                                                               DateTime.Now);

                    var configuration = MpObjectAttributeConfigurationFactory.GroupParticipant();
                    _objectAttributeService.SaveObjectAttributes(groupParticipantId, participant.AttributeTypes, participant.SingleAttributes, configuration);

                    if (participant.capacityNeeded > 0)
                    {
                        DecrementCapacity(participant.capacityNeeded, group);
                    }

                    _logger.Debug("Added user - group/participant id = " + groupParticipantId);

                    // Now see what future events are scheduled for this group, and register the user for those
                    var events = _mpGroupService.getAllEventsForGroup(Convert.ToInt32(groupId));
                    _logger.Debug("Scheduled events for this group: " + events);
                    if (events != null && events.Count > 0)
                    {
                        foreach (var e in events.Where(x => x.EventType != "Childcare"))
                        {
                            _eventService.RegisterParticipantForEvent(participantId, e.EventId, groupId, groupParticipantId);
                            _logger.Debug("Added participant " + participant + " to group event " + e.EventId);
                        }
                    }

                    if (participant.SendConfirmationEmail)
                    {
                        var waitlist = group.GroupType == _configurationWrapper.GetConfigIntValue("GroupType_Waitlist");
                        _mpGroupService.SendCommunityGroupConfirmationEmail(participantId, groupId, waitlist, participant.childCareNeeded);
                    }
                }
            }
            catch (Exception e)
            {
                _logger.Error("Could not add user to group", e);
                throw;
            }
        }