예제 #1
0
        /// <summary>
        /// Gets a list of groups with group attributes for either the logged in user or a participant you pass in.
        /// </summary>
        /// <param name="token"></param>
        /// <param name="participantId">if null we load the calling user's participant record</param>
        /// <param name="groupTypeId"></param>
        /// <param name="groupId"></param>
        /// <returns></returns>
        public List <GroupDTO> GetGroupsByTypeOrId(string token, int?participantId = null, int[] groupTypeIds = null, int?groupId = null, bool?withParticipants = true, bool?withAttributes = true)
        {
            if (participantId == null)
            {
                participantId = _participantService.GetParticipantRecord(token).ParticipantId;
            }
            var groupsByType = _mpGroupRepository.GetGroupsForParticipantByTypeOrID(participantId.Value, null, groupTypeIds, groupId);

            if (groupsByType == null)
            {
                return(null);
            }

            var groupDetail = groupsByType.Select(Mapper.Map <MpGroup, GroupDTO>).ToList();

            if (withAttributes == true)
            {
                var configuration = MpObjectAttributeConfigurationFactory.Group();
                var mpAttributes  = _attributeRepository.GetAttributes(null);
                foreach (var group in groupDetail)
                {
                    var attributesTypes = _objectAttributeService.GetObjectAttributes(token, group.GroupId, configuration, mpAttributes);
                    group.AttributeTypes   = attributesTypes.MultiSelect;
                    group.SingleAttributes = attributesTypes.SingleSelect;
                }
            }
            if (withParticipants == true)
            {
                GetGroupParticipants(groupDetail);
            }

            return(groupDetail);
        }
예제 #2
0
        public GroupDTO CreateGroup(GroupDTO group)
        {
            try
            {
                var mpGroup = Mapper.Map <MpGroup>(group);

                if (group.AttributeTypes.ContainsKey(_groupCategoryAttributeTypeId) && group.AttributeTypes[90].Attributes.Any(a => a.AttributeId == 0))
                {
                    var categoryAttributes = Mapper.Map <List <MpAttribute> >(group.AttributeTypes[90].Attributes);

                    categoryAttributes = _attributeService.CreateMissingAttributes(categoryAttributes, _groupCategoryAttributeTypeId);
                    group.AttributeTypes[_groupCategoryAttributeTypeId].Attributes = Mapper.Map <List <ObjectAttributeDTO> >(categoryAttributes);
                }

                group.GroupId = _mpGroupRepository.CreateGroup(mpGroup);
                //save group attributes
                var configuration = MpObjectAttributeConfigurationFactory.Group();
                _objectAttributeService.SaveObjectAttributes(group.GroupId, group.AttributeTypes, group.SingleAttributes, configuration);

                if (group.MinorAgeGroupsAdded)
                {
                    _mpGroupRepository.SendNewStudentMinistryGroupAlertEmail((List <MpGroupParticipant>)mpGroup.Participants);
                }
            }
            catch (Exception e)
            {
                var message = String.Format("Could not create group {0}", group.GroupName);
                _logger.Error(message, e);
                throw (new ApplicationException(message, e));
            }

            return(group);
        }
예제 #3
0
        public bool ParticipantGroupHasStudents(string token, int participantId, int groupParticipantId)
        {
            var groups  = GetGroupsForParticipant(token, participantId);
            var groupId = 0;

            foreach (var group in groups)
            {
                var participants = LoadGroupParticipants(group.GroupId, token);
                if (participants.Exists(x => x.GroupParticipantId == groupParticipantId))
                {
                    groupId = group.GroupId;
                    break;
                }
            }
            var configuration = MpObjectAttributeConfigurationFactory.Group();
            var attributes    = _objectAttributeRepository.GetCurrentObjectAttributes(token, groupId, configuration);

            return(attributes.Find(x => x.AttributeId == GroupHasMiddleSchoolStudents ||
                                   x.AttributeId == GroupHasHighSchoolStudents) != null
                                        ?true:false);
        }
예제 #4
0
        private void GetGroupAttributes(string token, List <GroupDTO> groups)
        {
            var configuration = MpObjectAttributeConfigurationFactory.Group();

            foreach (var attributeType in new[] { _groupCategoryAttributeTypeId, _groupTypeAttributeTypeId, _groupAgeRangeAttributeTypeId })
            {
                var types = _attributeRepository.GetAttributes(attributeType);
                foreach (var group in groups)
                {
                    var attributesTypes = _objectAttributeService.GetObjectAttributes(token, group.GroupId, configuration, types);
                    foreach (var multi in attributesTypes.MultiSelect)
                    {
                        group.AttributeTypes.Add(multi.Key, multi.Value);
                    }
                    foreach (var single in attributesTypes.SingleSelect)
                    {
                        group.SingleAttributes.Add(single.Key, single.Value);
                    }
                }
            }
        }
예제 #5
0
        public GroupDTO UpdateGroup(GroupDTO group)
        {
            try
            {
                var mpGroup = Mapper.Map <MpGroup>(group);
                _mpGroupRepository.UpdateGroup(mpGroup);

                List <MpGroupParticipant> groupParticipants = _mpGroupRepository.GetGroupParticipants(group.GroupId, true);

                if (groupParticipants.Count(participant => participant.StartDate < group.StartDate) > 0)
                {
                    UpdateGroupParticipantStartDate(groupParticipants.Where(part => part.StartDate < group.StartDate).ToList(), group.StartDate);
                }

                if (group.AttributeTypes.ContainsKey(_groupCategoryAttributeTypeId) && group.AttributeTypes[90].Attributes.Any(a => a.AttributeId == 0))
                {
                    var categoryAttributes = Mapper.Map <List <MpAttribute> >(group.AttributeTypes[90].Attributes);

                    categoryAttributes = _attributeService.CreateMissingAttributes(categoryAttributes, _groupCategoryAttributeTypeId);
                    group.AttributeTypes[_groupCategoryAttributeTypeId].Attributes = Mapper.Map <List <ObjectAttributeDTO> >(categoryAttributes);
                }

                var configuration = MpObjectAttributeConfigurationFactory.Group();
                _objectAttributeService.SaveObjectAttributes(group.GroupId, group.AttributeTypes, group.SingleAttributes, configuration);

                if (group.MinorAgeGroupsAdded)
                {
                    var leaders = groupParticipants.Where(p => p.GroupRoleId == _groupRoleLeader).ToList();
                    _mpGroupRepository.SendNewStudentMinistryGroupAlertEmail(leaders);
                }
            }
            catch (Exception e)
            {
                var message = String.Format("Could not update group {0}", group.GroupName);
                _logger.Error(message, e);
                throw (new ApplicationException(message, e));
            }

            return(group);
        }
예제 #6
0
        public List <GroupDTO> GetGroupsForParticipant(string token, int participantId)
        {
            var groups = _mpGroupRepository.GetGroupsForParticipant(token, participantId);

            if (groups == null)
            {
                return(null);
            }

            var groupDetail   = groups.Select(Mapper.Map <MpGroup, GroupDTO>).ToList();
            var configuration = MpObjectAttributeConfigurationFactory.Group();
            var mpAttributes  = _attributeRepository.GetAttributes(null);

            foreach (var group in groupDetail)
            {
                var attributesTypes = _objectAttributeService.GetObjectAttributes(token, group.GroupId, configuration, mpAttributes);
                group.AttributeTypes   = attributesTypes.MultiSelect;
                group.SingleAttributes = attributesTypes.SingleSelect;
            }

            return(groupDetail);
        }
예제 #7
0
        public GroupDTO getGroupDetails(int groupId, int contactId, MpParticipant participant, string authUserToken)
        {
            int     participantId = participant.ParticipantId;
            MpGroup g             = _mpGroupRepository.getGroupDetails(groupId);

            var signupRelations = _mpGroupRepository.GetGroupSignupRelations(g.GroupType);

            var currRelationships = _contactRelationshipService.GetMyCurrentRelationships(contactId, authUserToken);

            var events = _mpGroupRepository.getAllEventsForGroup(groupId);

            MpContactRelationship[] familyToReturn = null;

            if (currRelationships != null)
            {
                familyToReturn = currRelationships.Where(
                    c => signupRelations.Select(s => s.RelationshipId).Contains(c.Relationship_Id)).ToArray();
            }

            var apiToken        = _apiUserService.GetToken();
            var configuration   = MpObjectAttributeConfigurationFactory.Group();
            var attributesTypes = _objectAttributeService.GetObjectAttributes(apiToken, groupId, configuration);

            var detail = new GroupDTO();

            {
                detail.ContactId            = g.ContactId;
                detail.CongregationId       = g.CongregationId;
                detail.KidsWelcome          = g.KidsWelcome;
                detail.GroupName            = g.Name;
                detail.GroupDescription     = g.GroupDescription;
                detail.GroupId              = g.GroupId;
                detail.GroupFullInd         = g.Full;
                detail.WaitListInd          = g.WaitList ?? false;
                detail.ChildCareAvailable   = g.ChildCareAvailable;
                detail.WaitListGroupId      = g.WaitListGroupId;
                detail.OnlineRsvpMinimumAge = g.MinimumAge;
                detail.MeetingFrequencyID   = g.MeetingFrequencyID;
                detail.AvailableOnline      = g.AvailableOnline;
                detail.MeetingTime          = g.MeetingTime;
                detail.MeetingDayId         = g.MeetingDayId;
                detail.Address              = Mapper.Map <MpAddress, AddressDTO>(g.Address);
                detail.StartDate            = g.StartDate;
                detail.Participants         = (g.Participants.Count > 0) ? g.Participants.Select(p => Mapper.Map <MpGroupParticipant, GroupParticipantDTO>(p)).ToList() : null;

                if (events != null)
                {
                    detail.Events = events.Select(Mapper.Map <MpEvent, Event>).ToList();
                }
                //the first instance of family must always be the logged in user
                var fam = new SignUpFamilyMembers
                {
                    EmailAddress    = participant.EmailAddress,
                    PreferredName   = participant.PreferredName,
                    UserInGroup     = _mpGroupRepository.checkIfUserInGroup(participantId, g.Participants),
                    ParticpantId    = participantId,
                    ChildCareNeeded = false
                };
                detail.SignUpFamilyMembers = new List <SignUpFamilyMembers> {
                    fam
                };

                if (familyToReturn != null)
                {
                    foreach (var f in familyToReturn)
                    {
                        var fm = new SignUpFamilyMembers
                        {
                            EmailAddress  = f.Email_Address,
                            PreferredName = f.Preferred_Name,
                            UserInGroup   = _mpGroupRepository.checkIfUserInGroup(f.Participant_Id, g.Participants),
                            ParticpantId  = f.Participant_Id,
                        };
                        detail.SignUpFamilyMembers.Add(fm);
                    }
                }

                detail.AttributeTypes   = attributesTypes.MultiSelect;
                detail.SingleAttributes = attributesTypes.SingleSelect;
            }

            return(detail);
        }
예제 #8
0
        public IHttpActionResult GetGroupAttributes([FromUri] int groupId)
        {
            //var filter = new List<MpAttribute>
            //{
            //    new MpAttribute
            //    {
            //        AttributeTypeId = 90
            //    }
            //};
            var filter = _attributeRepository.GetAttributes(90);

            return(Authorized(token =>
            {
                var result = _objectAttributeService.GetObjectAttributes(token, groupId, MpObjectAttributeConfigurationFactory.Group(), filter);
                return Ok(result);
            }));
        }